Image Drawing error

Saj

Active Member
Licensed User
I'm trying to draw an image onto an existing image using dzt's library, but I can't get it to work. Sample code attached. Where have I gone wrong?
 

Attachments

  • forForum1.zip
    35.2 KB · Views: 203

klaus

Expert
Licensed User
Longtime User
Here you are, instead of using the dzImage library, I suggest you to only use the ImageLibEx you already use.
Drawing the 2nd image with a DrawerEx object.
This one allows to select with 2 RectEx objects the source rectangle and the destination rectangle. If the destination rectangle has a different size than the source rectangle the image is streched or compressed. The Width/Height ration can also be different.

Attached the sbp file.

Best regards.
 

Attachments

  • dZdraw_forum_New.sbp
    1.1 KB · Views: 198

Saj

Active Member
Licensed User
Thanks for pointing this out Klaus.

I didn't explain myself clearly in the 1st post. What i'm trying to do is copy a a number of small images (i.e. tiles) onto a larger image (i.e. map) and then showing the larger image on a form. I've had a go at doing this using New2 but can't get it to work. See attachment.
 

Attachments

  • dZdraw_forum_New2.sbp
    1.7 KB · Views: 202

Saj

Active Member
Licensed User
I'm trying to copy an image from an ImageListArray to a bitmap:

bmpTile.New3(tilesImageListArr.Item(i)) 'where bmpTile is bitmapEx object

I get an error stating "Parameter is not valid". Can an image not be passed to an bitmapEx object is this way?
 

klaus

Expert
Licensed User
Longtime User
What do you want to do with it?
If you want to draw the tiles onto the form, this works:
B4X:
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]drwMap.DrawImage(tilesImageListArr.Item([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]),rectTileSrc.Value,rectMapDest.Value,[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]False[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT][/SIZE][/FONT]

Best regards.
 

Saj

Active Member
Licensed User
Hi Klaus

I'm basically trying to assign a bitmap from (a) memory if previously loaded or (b) re-load if not found in memory. My thinking is that it be quicker to draw the tile from memory rather than reloading everytime from file. Below is the code i'm trying to use it in. It suitabily comment to see whats happening:




'1a Get handle "bmpTile" To tile file by (a) copying from ImageListArr If already loaded OR (b) re-laoding from jpg tile file:
For i=0 To ArrayLen(tilesCurrentlyInImageListArr())-1 'Note 'i' corresponds to tile posn on canvas as it cycles through, not mosaic, 1st posn (i.e. top left corner) is zero
If tilesCurrentlyInImageListArr(i).tileIndexOnMosaic = tileIndexOnMosaic1 Then
'Tile already loaded in ImageListArr
''#bmpTile.Create3(tilesImageListArrC.Item(i)) 'Assign tile as bmp from ImageListArray
bmpTile.New3(tilesImageListArrC.Item(i))
tilesImageListArrC.Item(tilePosnOnCanvas) = tilesImageListArrC.Item(i) 'Copy tile to correct posn in imageListArr for future use
tilesCurrentlyInImageListArr(i).tileIndexOnMosaic = tileIndexOnMosaic1 'Update array to keep track of what has been moved/copied
tileFoundinImageListArr = True
Msgbox ("Found in ImageListArr: " &CRLF& "tileIndexOnMosaic1=" & tileIndexOnMosaic1 & "; "& tileRowPosninMosaic&"-"&tileColPosninMosaic)
Exit 'tile loaded, so exit ForLoop
End If
Next

If tileFoundinImageListArr=False Then
'tile not found in ImageListArr (i.e. not already loaded), therefore load from file
tilefile = AppPath & "\tiles\" & tileFileNamePrefix & "-" & tileRowPosninMosaic & "-" & tileColPosninMosaic & ".jpg"
bmpTile.Create1(tilefile) 'Assign tile as bmp
tilesImageListArrC.Item(tilePosnOnCanvas) = bmpTile.Value 'Copy tile to imageListArr for future use
tilesCurrentlyInImageListArr(tilePosnOnCanvas).tileIndexOnMosaic = tileIndexOnMosaic1 'Update array to keep track of what has been copied
End If

'1b. Define source image area (i.e. WHOLE tile):
rectTile.X = 0 'Q: move to LoadMap as it it constant?
rectTile.Y = 0 'Q: move to LoadMap as it it constant?
rectTile.Width = TileWidth
rectTile.Height = TileHeight
'1c. Define destination image area (on canvas):
rectTileDestOnCanvas.X = x_pix_onCanvas
rectTileDestOnCanvas.Y = y_pix_onCanvas
rectTileDestOnCanvas.Width = tileWidth*zoom
rectTileDestOnCanvas.Height = tileHeight*zoom
'1d. Draw tile onto right position on canvas:
canvasDrawer.DrawImage(bmpTile.Value,rectTile.Value,rectTileDestOnCanvas.Value,False) 'copy tile onto canvas, zoomed as req'd
 

Saj

Active Member
Licensed User
It complies ok. The error occurs ar runtime - attached. I have checked the size of the imagelist array just before the error and this was ok.
 

Attachments

  • error1.jpg
    error1.jpg
    16.8 KB · Views: 199
Top