Solved

How to display Gif89a with transparent color other than black

Posted on 2000-02-28
3
249 Views
Last Modified: 2010-04-06
I would like to know how can I display a GIF89a file with tranparent color other than black. The popular browsers do it but I want to do this in my own program written in C++ for Windows 95 (and higher). If transparent color is black I made a mask for image replacing all black pixels by white ones and the others by the white ones and next I used two BitBlt's, the first with the mask and AND ROP-code and the second with the image and the OR ROP-code. But if a transparent color is other than black this method obviously doesn't work. Nevertheless the browsers know how to resolve this problem.  Do you know any method for C++ Windows program ?
Thank you in advance for any response
0
Comment
Question by:rainette
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
nils pipenbrinck earned 100 total points
ID: 2568380
Yes, you can do that.

I don't know how you load your gif-files.. I think you use a third party library for that.. take a look at the documentation how to get the transparent color index.

If the library don't support this, you can write a code which opens the gif yourself.. just scan the header for the extension flag and extract the transparent color index (if present). You only need the header, the hard part (decoding the image data) can still be done by your existing code.

here is a documentation of the fileformat:

http://www.cubic.org/source/archive/fileform/graphic/gif/gif89a.txt

After you know which of the 256 colors is your transparent color, you can simply build your and/or mask based on that color. It's nothing more than a simple loop which iterates over the pixels and sets the pixel in the mask based on the pixel color... A quite easy job I think.

Hope that helps.. I cannot give you sourcecode, because I've never dealed with transparent gif files myself..

Regards,

  Nils Pipenbrinck
0
 

Author Comment

by:rainette
ID: 2569083
I load GIF-files with my own procedure which is slightly modified code from Nabayoti Barcacati's book on Borland C++ programming. But WHAT IS "A THIRD PARTY LIBRARY" ? Thanks to your hint I think that I found a better one: instead to change pixels I will change color values in appropriate color palette place.
( GIF-files I know always use color palettes. )
For image I'll change color value for transparent color index to black ( RGB(0,0,0) ), for mask - I'll change this value to white( RGB(255,255,255) ) and all the other values to black. Is it a good idea ?
0
 
LVL 4

Expert Comment

by:nils pipenbrinck
ID: 2569148
changing the palette-entry is a good idea.. and it'll always work since there aren't any gif files without palette.

what's a third party library? that's a library you buy don't write yourself but buy somewhere... Like for example you want to use a library that handles thousands of fileformats you'll better buy something instead of spending a year developing and debugging it yourself.

Nils
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Flash movie or gif/animation? 3 890
CorelDraw X7 photo printing on 4x6 6 72
Saving html pages from the web 5 90
Lite dgn, dwg free viewer 1 116
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now