Trouble with Pixmaps
BlitzMax Forums/BlitzMax Beginners Area/Trouble with Pixmaps
| ||
Graphics 800,600 Local Image = LoadImage ("Images/Cursor.png") DrawImage(Image, 0,0) Local Cheese:tpixmap = LockImage(Image) DrawPixmap(Cheese, 64, 0) Flip Delay 5000 The image "Cursor.png" is an arrow with a pixel thin orange outline, in the image from the Pixmap this outline is now 2 pixels thick Cheese = ColourSub(Cheese,0,0,128,200,140,0,32,19) Function ColourSub:Tpixmap(Image:Tpixmap,OldR,OldG,OldB,NewR,NewG,NewB,w,h) MaskPixmap:Tpixmap(Image, OldR,OldG,OldB) SetClsColor NewR,NewG,NewB Cls DrawPixmap Image:TPixmap, 0, 0 Image = GrabPixmap:TPixmap (0,0,w,h) SetClsColor 0,0,0 Return Image End Function The function seems not to modify the pixmap at all, when I draw it out again after calling the function, it looks just like it did when it went in I have checked the colour codes in MS Paint, 0,0,128 does indeed make up the main body of the arrow |
| ||
I'm not surprised it doesn't look different. Masks don't have any effect on pixmaps. I'm guessing (cos I'm not entirely sure what you are tryin to do), but I think you may need to draw the image using DrawImage instead of DrawPixmap, before you grab it using GrabPixmap. |
| ||
ok, ChangingMaskPixmap:Tpixmap(Image, OldR,OldG,OldB) to: Image = MaskPixmap:Tpixmap(Image, OldR,OldG,OldB) Did have some affect, unfortunatly it wasnt what I was hoping for it created a transparent area, and the colours around it all advanced 1 pixel further into the transparent area MaskPixmap returns a new Pixmap with pixels of the specified colour made transparent There are good reasons I cant use Images here, you cant mask them directly anymore, only upon load or when modified, which is very unhelpful indeed |
| ||
But IMO it would be better to readpixel/writepixel to do this sort of thing. |
| ||
Wow, I am such an atrocious programmer Not only have I been unable to solve a single problem I've had with max on my own so far, but every document I've found on Alpha Blending in response to reading that post has either been irrelevant or just gone way over my head -Edit: Nevermind, figured the above out, that could be very useful later- I dont understand how I would handle the output of ReadPixel, or construct input for Write pixel either |
| ||
I dont understand how I would handle the output of ReadPixel, or construct input for Write pixel either Strict Graphics 800,600,0 Local Image:Timage = LoadImage ("Cursor.bmp") DrawImage(Image, 0,0) ColourSub(Image,0,0,128, 200,140,0) DrawImage(Image, 64, 0) Flip Delay 5000 Function ColourSub(Image:TImage,OldR,OldG,OldB,NewR,NewG,NewB) Local Pix:TPixmap = LockImage(Image) Local x:Int, y:Int Local OldColour:Int = (255 Shl 24)|(OldR Shl 16)|(OldG Shl 8)|OldB Local NewColour:Int = (255 Shl 24)|(NewR Shl 16)|(NewG Shl 8)|NewB For x=0 Until PixmapWidth(Pix) For y=0 Until PixmapHeight(Pix) If ReadPixel(Pix,x,y) = OldColour WritePixel(Pix,x,y,NewColour) EndIf Next Next UnlockImage(Image) End Function |
| ||
Ok, General question, do Pixmaps always store things as these argb values? If so I imagine that this would vastly restrict the number of shades you can have, the difference between 0->7 for R, G or B, and 0->255 for R, G, and B is pretty huge Edit: Please, dont write code for me, I'm not asking for that, I thank you for the effort, but I'd rather just have some hints in the right direction so I can figure it out for myself, I'm never going to get anywhere if people are just writing my code for me |
| ||
0->7? dont panic its still stored as 0->255, its just all packed into one int. http://en.wikipedia.org/wiki/ARGB |
| ||
Aha, its in Hex, that explains it ty very much, I think I can write a working function now |