Masking pixels in a created pixmap
BlitzMax Forums/BlitzMax Beginners Area/Masking pixels in a created pixmap
| ||
ive made a pixmap using alot of pixel writing and some use of grabimage. Anyway i can't get the resulting image to mask. its a 128x128 isometric tile with black spaces round the edges. Ive tryed the blend modes which normally work but ive not got anywhere. help :O) |
| ||
none of the 3d graphics commands work with pixmaps. you need to convert it to a Timage and use it that way. image:TImage = LoadImage(pixmap:tpixmap) |
| ||
Function SetImageMask(p_image:TImage, p_red:Int,p_green:Int,p_blue:Int) Local l_maskrgb:Int Local l_maskargb:Int Local l_pixelrgb:Int Local l_pixelraw:Int Local l_x:Int,l_y:Int Local l_pix1:TPixmap l_maskrgb = p_red Shl 16 + p_green Shl 8 + p_blue l_pix1 = LockImage(p_image) For l_x = 0 To ImageWidth(p_image)-1 For l_y = 0 To ImageHeight(p_image)-1 l_pixelraw = ReadPixel(l_pix1,l_x,l_y) l_pixelrgb = l_pixelraw & 16777215 If l_pixelrgb = l_maskrgb Then ' make transparent WritePixel(l_pix1,l_x,l_y,l_maskrgb) Else ' remove transparency Local l_PixelNoAlpha:Int=l_pixelrgb | (255 Shl 24) WritePixel(l_pix1,l_x,l_y,l_PixelNoAlpha) End If Next Next UnlockImage(p_image) End Function |
| ||
you can have cumulative masking by commenting out the 'remove transparency' part.. I assume you can mine the function for what you need.. |
| ||
I don't think that is what he wants. I believe he is trying to display a pixmap to the screen as if he is displaying an image and the pixmap is being drawn including the black pixels to the screen which he doesn't want to happen. |
| ||
Anyway i can't get the resulting image to mask make sure you set DYNAMICIMAGE|MASKEDIMAGE when you create the image... |
| ||
ok i will give all the above a go thanks for your help :O) Pete |
| ||
sorry but should this mask all the bright pink pixels?nomask:TPixmap = GrabPixmap:TPixmap(128,64,128,64) masked:Timage = LoadImage(nomask:TPixmap,DYNAMICIMAGE|MASKEDIMAGE) SetMaskColor(255,000,255) SetBlend(MASKBLEND) DrawImage(masked:Timage,0,0) |
| ||
got it working with black. id rather it was bright pink though as i may want black in may images. |
| ||
It should work for any color.. I currently use it to set the mask on several tilesets. If you peek the color from the pixelmap you ensure the correct mask color |
| ||
I found out what it was! i had to setmaskcolor before loading the image. now it works perfect. thanks again |
| ||
Thats the proper way of doing it lol... you don't need the function if you do it that way. If you're setting mask after loading them you need the function I posted. Perhaps I should have mentioned that but I didn't know why you needed to set the mask...just that you needed to set the mask lol |