PNG transparent colour
BlitzMax Forums/BlitzMax Programming/PNG transparent colour
| ||
Okay, so you know you can nominate a colour as transparent in clutted PNGs in art packages? How can I find out what that colour is so I can set it as the maskimage value? |
| ||
I don't think you need to. You load in the PNG that you saved with the transparent colour; make sure you use MASKEDIMAGE with LoadImage and it should just work (well it does for me but I could be wrong). |
| ||
Probably you need to start the graphics mode with an alpha buffer too, but I'm not sure. |
| ||
Righty, ta'. Also, I just realised I should have posted this in the BlitzPlus part. Dammit dammit dammit! |
| ||
Edit.Sorry I hasetated and posted. |
| ||
well everything I said is invalid then, cos it doesn't apply to BlitzPlus. In Blitplus, use the art package "dropper" over a background pixel, it should say 0,0,0 if black or 255,0,255 if magenta whatever, set this as the MaskImage value in BlitzPlus and it will work fine. |
| ||
That's no use to me, though, because BlitzPlus messes up the colours when it loads a PNG with transparency, setting the transparent colour pixels to white. Also I think loading each image into an art package to determine the background colour isn't really a viable option either, is it? PNGs have transparency information for a good reason. |
| ||
If you use PNG with transparency channel, make sure you set the blendmode to alphablend before drawing. If you want to use masking, I would suggest using the pixel at 0,0 as "mask reference pixel". Load it as pixmap, read the pixel value, use setmaskcolor with that value and then load an image from the previously loaded pixmap with the above stated MASKEDIMAGE flag (loading image from file would not be faster as it does internally load a pixmap first as well) |
| ||
B+ can't handle transparency. Instead you can specify a colour (default black) to act as transparent. If you do not intend to use black as the transparent colour you need to use maskimage and specify the RGB values. If you don't know the transparent colour how can B+? That's why you either... a) Need to provide the RGB if you know it b) Open the image into a paint package and find the RGB to give to B+. |
| ||
That's no use to me, though, because BlitzPlus messes up the colours when it loads a PNG with transparency, setting the transparent colour pixels to white. Actually, that would be Photoshop. |
| ||
hmm, I already told him what to do on my second post in a concise manner, oh well. I guess having it said different ways can only help :-) except for the BlitzMax advice haha. DrDerekDoctors: If it sets the pixels to white, make your mask colour 255,255,255. Better still switch off the transparency and just fill your background with a colour that's not in use in the main graphic (such as magenta 255,0,255) and set this to the mask colour in your game. It's what I do (did) in BlitzPlus. |
| ||
1) If it's something caused by the art package then I can't guarantee it'll always be white. Also, the images aren't from Photoshop, they're from a variety of packages. 2) If there's real white in the image, that'll get messed up by the tranparency being set to white, wouldn't it? I'm talking about PNGs which I haven't created, ones which could come from anywhere which don't all have the same mask colour set as the transparent one in their palette. All I want to do is for Blitz to actually do it's job properly. |
| ||
B+ (in this case) *is* doing it's job properly. It does not do transparency (think it's because DX1 doesn't do it) so needs you tell it which colour to ignore. If an image is loaded WITH a transparent colour it will be replaced by white (255,255,255). I'm sorry if you've got a load of downloaded images with transparency but you'll have to bite the bullet and change them. |
| ||
or just save them all as bitmaps, thus forcing a background colour, then resave as png without transparency info. Maybe just resave as png without transparency info and see what the background colour turns out to be. |
| ||
The images aren't mine, this is for a program which'll be used by other people so I don't think it's reasonable to ask them to change all their stuff. Also asking them to change them to bitmaps isn't really an option, either. |
| ||
... then B+ is probably not the tool for the job. You're trying to provide a program to read images with transparency written in a language that doesn't allow transparency. B3D could handle it and so can BlitzMax. |
| ||
You could write a function to import PNGs with alpha as PNGs with a predictable mask colour. I use something similar to convert 'white-alphas' (thanks, PhotoShop) into 'black-alphas'. The function loads a PNG as a pixmap, scans it for pixels with an alpha of zero, and sets those pixels to the mask colour.' Process image to turn transparent pixels black so sprites don't display a white fringe when filtered. Global CrescentPixmap:TPixmap = LoadPixmap( "incbin::Resources\Graphics\Crescent.png" ) For Local yi = 0 To CrescentPixmap.height - 1 For Local xi = 0 To CrescentPixmap.width - 1 Local p = ReadPixel( CrescentPixmap, xi, yi ) If p & $FF000000 = 0 WritePixel( CrescentPixmap, xi, yi, 0 ) EndIf Next Next Global CrescentImage:TImage = LoadImage( CrescentPixmap, FILTEREDIMAGE ) |
| ||
Hmmm, it might be slow but you could set any 0,0,0 pixels to 5,5,5 before changing zero alpha pixels to black. |
| ||
The images aren't mine, this is for a program which'll be used by other people gosh you are a little spartan with this vital info. Yeah as TonyG said, get blitzMax and be done with it. Or if you are feeling brave, do what Wayward said haha. |
| ||
Trust me, as soon as someone else posts a solution, I'm gonna' invent another spanner to throw into the works. ;) I think I need to get Bmax and the GUI plugin I suppose. Ah well. |
| ||
Hello. If people are going to be loading their own images why not provide the functionality within the program for them to choose the transparent colour themselves? Goodbye. |
| ||
I'm gonna' have to do that, but really it's something they shouldn't have to do. |
| ||
... that's right. Somebody should be doing it for them by using a product which allows for transparency. |
| ||
You mean like Gimp, PhotoShop, PaintShopPro, Pixia ( the first and the last are free) |
| ||
... no like BlitzMax. |
| ||
Given that part of PNGs spec is that you can nominate a transparent colour I'd say that Blitz+'s PNG loading is incomplete and broken if it doesn't use that information in the proper manner, surely? Anyhoo, looks like my company is gonna' spring for BMAX - I assume that with applications I can use nice variable transparency levels in the windows (ie, see-through stuff, nothing to do with the image's alpha channel)? |
| ||
yep P.S. Don't think it is B+ fault but DirectDraw. Obviously the decisions to use DX1 might be questioned. Does B+ really use DX1? |
| ||
But as a mather of fact, you don't have alpha in 2D so it makes no sense in loading those information. BM on the other side is full 3D and in 3D, alpha exists, so it makes sense to load the data. |
| ||
B+ does support nominating a mask colour, though, so it makes sense if there's information available in a file pertaining to that to actually use it. |