Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
cbpporter is currently offline  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 #32552 is a reply to message #32547] Tue, 24 May 2011 17:46 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3378
Registered: August 2008
Senior Veteran
Hello Cbpporter

Do you want to show the new image or to save it?


Best regards
Iñaki
Re: How to make a non transparent image transparent [message #32561 is a reply to message #32552] Tue, 24 May 2011 22:48 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1406
Registered: September 2007
Ultimate Contributor
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.
Re: How to make a non transparent image transparent [message #32564 is a reply to message #32561] Wed, 25 May 2011 08:45 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

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. ).
Re: How to make a non transparent image transparent [message #32565 is a reply to message #32564] Wed, 25 May 2011 08:55 Go to previous message
koldo is currently offline  koldo
Messages: 3378
Registered: August 2008
Senior Veteran
It looks good.

Best regards
Iñaki
Previous Topic: SetSurface, shrink, stretch?
Next Topic: Printing without dialog
Goto Forum:
  


Current Time: Wed Jul 24 21:22:08 CEST 2024

Total time taken to generate the page: 0.01075 seconds