Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to display Gif89a with transparent color other than black

Posted on 2000-02-28
3
Medium Priority
?
257 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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…
Suggested Courses

916 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