Create an image on a blank canvas
BlitzMax Forums/BlitzMax Programming/Create an image on a blank canvas
| ||
I'm hoping that someone will be able to help me with a query on images in BlitzMax. What I want to do is create a new image and paste another onto it. The code I'm currently using I've cribbed from this forum but it seems to allow black pixels to become transparent, which I don't want. How can I adapt this code to paste a picture into a larger black picture? Function InsertImage:timage(src:TImage,destx:Int,desty:Int,srcFrame:Int,dest:TImage) Local dmap:TPixmap = LockImage(dest) Local smap:TPixmap = LockImage(src,srcFrame) For y=0 To dest.height-1 For x=0 To dest.width-1 WritePixel(dmap,x,y,$0:Int) Next Next For y:Int =0 To ImageHeight(src)-1 For x:Int=0 To ImageWidth(src)-1 color:Int = ReadPixel(smap,x,y) color=(color & ($FFFFFF:Int)) | $FF000000:Int pixX=x+destX pixY=y+desty err=0 If pixX<0 Or pixX>dest.width-1 err=1 End If If pixY<0 Or pixY>dest.height-1 err=1 End If If err=0 WritePixel(dmap,x+destx,y+desty,color) End If Next Next UnlockImage(src,srcFrame) UnlockImage(dest) Return dest End Function Thanks in advance. |
| ||
Easy option is to draw them then grab them or use pixmap paste method |
| ||
http://www.blitzmax.com/Community/posts.php?topic=74153 The lower code sample is the one to get as it has some bugs fixed Might be of use depending on exactly what you're going for. It's very straight forward and easy to modify, I've torn it to bits to suit my needs but now mine will draw one image on another with a replace color for white if I need, or blank areas with a mask graphic, and will set empty pixels for white for alpha blending so they don't get blacked out. if you're using the alpha feature then I would recommend changing the alpha blend portion to sourceR = (1 - (sourceA/255)) * destR + (sourceA/255) * sourceR sourceG = (1 - (sourceA/255)) * destG + (sourceA/255) * sourceG sourceB = (1 - (sourceA/255)) * destB + (sourceA/255) * sourceB as it wasn't working correctly for me as sourceR = (sourceR * light * sourceA / AlphaSum) + destA / AlphaSum * (destR * destA / AlphaSum) sourceG = (sourceG * light * sourceA / AlphaSum) + destA / AlphaSum * (destG * destA / AlphaSum) sourceB = (sourceB * light * sourceA / AlphaSum) + destA / AlphaSum * (destB * destA / AlphaSum) I didn't use the light feature so I chopped that you, but you could add it back in if you wanted it... |
| ||
or use pixmap paste method..Graphics 800,600 Local mypix1:TPixmap = LoadPixmap("max.png") Local mypix2:TPixmap = LoadPixmap("player1.png") mypix1.paste(mypix2,0,0) Local myimage:timage=LoadImage(mypix1) While Not KeyHit(KEY_ESCAPE) Cls DrawImage myimage,0,0 Flip Wend |