need image with an alpha channel
Community Forums/General Help/need image with an alpha channel
| ||
so I have this black and white only image saved as a png file.![]() For my game I need it in a form where it has an alpha channel that corresponds to the colors... in other words I want an image to have an alpha channel that corresponds to the brightness of this image... sorry im not sure exactly how to word it. Anyway, I tried using photoshop but I couldnt figure that out and paint doesnt save png's with an alpha channel. Is there any code to do this or does anyone know how to make png's with an alpha channel in code? Last edited 2011 |
| ||
You can use the GIMP for this quite easily, by going to Layer -> Mask -> Add Layer Mask and choosing "Grayscale copy of layer". |
| ||
wow thanks! Thats exactly what I needed... GIMP is awesome btw, I can't stop playing with it now! |
| ||
GIMP is indeed awesome. Here's a simple blitzmax function to do the same sort of thing. Uses (Red+Green+Blue)/3.0 as the alpha channel. Should be easy to customise if you need to. Function createMaskAlphaLayer:TPixmap(pixmap:TPixmap) Local pixelCount:Int = PixmapWidth(pixmap)*PixmapHeight(pixmap) Local pm:TPixmap = ConvertPixmap(pixmap,PF_RGBA8888) Local i:Int Local src:Int Ptr = Int Ptr(PixmapPixelPtr(pm)) Local argb:Int Local alpha:Int For i = 0 To pixelCount-1 argb = src[i] alpha = ((argb & $FF) + ((argb Shr 8) & $FF) + ((argb Shr 16) & $FF))/3.0 src[i] = (argb & $00FFFFFF) | alpha Shl 24 Next Return pm End Function Hope that helps. |