473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Scaling transparent GIF / Transparency gets black

Hi all

I am new here and i hope i do not make any mistakes with this question.

I try to change a GIF-File that contains transparency. The problem lies within the following code:

Expand|Select|Wrap|Line Numbers
  1. ' Open a gif with transparency
  2. Dim nBm As Bitmap = New Bitmap("C:\Temp\TestTransparent.gif")
  3.  
  4. ' Create a new bitmap with the same size
  5. Dim nResult As Bitmap = New Bitmap(nBm.Width, nBm.Height)
  6.  
  7. ' Get a graphics object
  8. Dim nGr As Graphics = Graphics.FromImage(nResult)
  9.  
  10. ' Draw the old bitmap to the new one
  11. nGr.DrawImage(nBm, New Point(0, 0))
  12.  
  13. ' Make black transparent
  14. nResult.MakeTransparent(Color.Black)
  15.  
  16. ' save the whole thing as gif
  17. nResult.Save("C:\Temp\TestTransparent_Neu.gif", Imaging.ImageFormat.Gif)
Problem after that: all transparency has gone black in the resulting gif.

The purpose of the code at the end should be to reduce the gif in size. So i have to build a new bitmap out of the old.

I searched for "gif transparent", "transparent black", DrawImage transparent" and found nothing to help me on. Also google is not my friend in this case. Many tips, most for java or browsers.

I post this in the .net-forums. I dont think that this is a VB- or C#-issue. Correct me if i am wrong.

Greetings
Alex
Apr 20 '09 #1
8 3738
ram09
45
so your problem is that, when you reduce the size of your gif file, the transparent portion became black? is this a web proj?
Apr 22 '09 #2
@ram09
Hi ram09

should there be a difference? I need the (smaller) GIF for a web-project. But it should work independent of web or not web.

Alex
Apr 22 '09 #3
ram09
45
i think theres no difference..i just want to clarify your problem... so you want to manipulate a .gif image file dynamically?? and you had this problem when you resize the image?
Apr 22 '09 #4
@ram09
Yes. I have to create a thumb of a GIF-file and the transparency has to be transformed also (some gifs overlap each other, so the transparency is important).

Alex
Apr 22 '09 #5
ram09
45
I think you also need to consider the image file that you manipulated, if you edit the image itself properly, without any background if you want it to be transparent.... have you tried using other image files?? .png is also a good image file when you have some transparency...
Apr 22 '09 #6
@ram09
Sorry, ram09, i have no choice here. I have to use the gif-files.

Alex
Apr 22 '09 #7
Hi,

the following steps should help:

a) Save image to memory stream as GIF with 89a version
b) Load image from memory stream
c) Detect transparent color from the image palette (Hint: component A is zero)
d) Take a GIF file description
e) Walk through the bytes on the stream and get color the index of your transparent color (Hint: MS often stores more than one equal entry in the palette, use the highest color index)
f) Ensure that transparency flag in "Flags" of the "Graphic Control Extension Bock" is set
g) Set the "Transparent Color Index" in the same block
h) Load the image again from the stream

Now you have a transparent GIF in your image instance and on the stream.


Regards

Holger
May 6 '09 #8
Hi Holger

a very complex solution. I will try that and report the result. Thanks for your help.

Alex

PS: und Grüße aus Bayern!
May 6 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Josip Maslać | last post by:
Hello. My task/problem is this: I've made a script that takes images (in gif,jpg & png) and makes their thumbs in jpg format. Now, the problem is if I have a transparent gif when saved to jpg...
0
by: Meken | last post by:
Hi, When I'm resizing .gif images in my asp.net application the transparent background gets black. Can anyone give me some advise or even better some code example how to keep the background...
0
by: Xavier Valdés | last post by:
Hi all, I'm trying to see files from listview control so I'm adapting VBResourcekit sample "Windows Forms - Create an Explorer Style Application" with different icons capabilities. For doing...
2
by: Xavier Valdés | last post by:
Hi all, I'm trying to see files from listview control so I'm adapting VBResourcekit sample "Windows Forms - Create an Explorer Style Application" with different icons capabilities. For doing...
2
by: Xavier Valdés | last post by:
Hi all again, I've written three times in this "managed" newsgroup but no post at all... I'm trying to see files from listview control so I'm adapting VBResourcekit sample "Windows Forms -...
3
by: James | last post by:
Hello, I use to use borland c++ where I would create an image (with a black background), and a mask (with a white background, where the image is black). I would then And the mask and or the...
2
by: Mark Denardo | last post by:
Hi, I need some expert GDI+ person to help me with my RoundOffImage Function: What I'm trying to do is take in an image, crop off the edges around an ellipse region I set up, and then return the...
1
by: Aleksey | last post by:
Hi, guys! How can I make ListView to be transparent? Transparency in C# seems to be a problematic part at all. It's not truly transparency I used to in Delphi. Thanks a lot
1
by: Aleksey | last post by:
Hi, guys! How can I make ListView to be transparent? Transparency in C# seems to be a problematic part at all. It's not truly transparency I used to in Delphi. Thanks a lot
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.