Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » How to make a non transparent image transparent
How to make a non transparent image transparent [message #32547] |
Tue, 24 May 2011 13:19 |
cbpporter
Messages: 1406 Registered: September 2007
|
Ultimate Contributor |
|
|
I searched though the sources, but I couldn't find a method to convert an image loaded from a file without any transparency information into a transparent one. I want to replace one single color with completely transparent pixels. I am not using IML and am not able to use it.
The algorithm is simple and I can code it with ease, but would like to know if there is support for this out of the box?
|
|
|
|
|
Re: How to make a non transparent image transparent [message #32564 is a reply to message #32561] |
Wed, 25 May 2011 08:45 |
|
cbpporter wrote on Tue, 24 May 2011 23:48 | Show it, save it, do normal image stuff with it. I have the code for doing this and I can contribute it if the method does not exist. Wrote it today and generated hundreds of PNGs with it.
My question is: does it exist? If the method exists and I did not find it yet, I need to adapt my code to use the out of the box method.
|
In this case is very easy:
FileIn in(filename);
One<StreamRaster> r = StreamRaster::OpenAny(in);
if(!r)
return Image();
Image img = r->GetImage();
ImageBuffer b(img);
RGBA *s = ~b;
RGBA *e = s + b.GetLength();
RGBA fc;
fc.r = 0;
fc.g = 16;
fc.b = 156;
fc.a = 0;
while(s<e){
if((s->r==fc.r)&&(s->g==fc.g)&&(s->b==fc.b))
s->a=fc.a;
++s;
}
Don't forget to add required packages in your package (e.g.: Draw, plugin/png, plugin/tif, plugin/jpg, ..., etc. ).
|
|
|
|
Goto Forum:
Current Time: Sat Sep 07 12:42:54 CEST 2024
Total time taken to generate the page: 0.05755 seconds
|