Tnasparent JPEG

I have many large pictures that need to display them with a transparent background. The JPEG gives me the best compression on these images then I prefer to use JPEG format. I tried to change pictures to bitmap and apply transparency to bitmap when I need to display them but pictures show as noisy.

There is any way to show JPEG images with a transparent background? Or do you know any other compression algorithm with power of the JPEG compression.

Thanks in advance for you help.

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

TheNeilConnect With a Mentor Commented:
Another compression system for images. Hmmmm. It all depends what you're trying to store. If you're storing 16.7m colour images (espcially scanned images) then JPEG is your best bet (fractal comprfession is even beter but far too slow) but whatever format you use you'll hit your original problem.

You would be a lot better off using 256 colour images - they're smaller, there are a lot more formats that handle it, they are usually NON-lossy (no quality loss), and you have a better chance of solving your original problem. I would suggest GIF but you say EXCEPT GIF then my next suggestion would be PCX. It might be a bit old but it's really easy to understand (and therefore code if you want to do it all by hand rather than get a component) and offers fairly good compression on images that have a lot of flat colour BUT if you're dealing with scanned images or images which DON'T have a lot of flat colour then it can be really INefficient.

What type of images are you dealing with?

The Neil
JPEG compression works by being 'lossy' and because of this you won't be getting flat colour anymore which is why your Bitmap approach won't work (transparency works on only one colour but the 'flat' areas of your image are now made up of several colours). There isn't anything that offers JPEG compression that ISN'T lossy so you're going to hit this problem all the time.

A possible solution is to convert the JPEG to Bitmap (as you tried) and then go through the image and replace all the colours SIMILAR to the one that you want to make transparent (e.g. if you're treating black as transparent then replace all the colours CLOSE to black to actual black). Sadly this is a slow process as you're processing the image on a pixel level. Things can be sped up a lot by using scanlines.

If you need some sample code then just ask.

The Neil
kambizAuthor Commented:
Thank you Neil,

Do you know other image format (except GIF) or any other compression algorithm that can be used for my situation.

The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

My advise is to use bitmap, because it is large file, but faster in display, all other format's like tiff, fractals, jpeg, gif, or any other format, they will be small size, but slower in display, especially if they are very large images.

so if you are plan to store your bitmaps in your exe (not advised), you willhave a large exe file, but the as you know, the user dose not care for some more time at load time, if you comapre it in the diplay time...
Kambiz : I've done this kind of stuff before.  If you like, email me a zip file of your code and JPEGs and I'll go through it for you. (


kambizAuthor Commented:
Thanks everybody,

I found my mistake by The Neil's comment. Thank you Neil. I actually need 256 colors and I have used 16.7m colors. Why? I don't know.

But there is another problem. Let I first explain more about my job.

I have written an Office 97 Assistant package (for public domain) with all features that you have seen in Office 97. For animations, I have provided a special formats because each frame of the animation can be had a sound and many branches. I also have provided an editor to create actor of the assistant (This cause the problem). The actor actually is a DLL that loads by the assistant component. Each actor has at least 64 animations with average 15 frames. Animations store as LZH compress format.

Now the problem:
If I reduce the color depth to 256 color I will have about 60% reduce in the actor size.
Reducing the color depth cause the image loses its colors. The error diffusion method gives the best appearance for reducing the color depth but I don't know its algorithm.

John, If you still have a solution, I’m ready to send you the source of the actor editor.

Thank you again,

Kambiz - Okay, let's have a look at it.  (I'll do my best for ya!)

kambizAuthor Commented:
Thank you friends. I solved my problem and the Neil's comment leads me to the solution. I give points to The Neil.

John - You can download the Package and the Actor Editor from my homepage about 10 days later.
All Courses

From novice to tech pro — start learning today.