473,216 Members | 1,274 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,216 software developers and data experts.

System.Drawing.Image.Save() on Transparent GIF

I am creating GIF images with transparent backgrounds on-the-fly for a web
app and rendering them by using
System.Drawing.Image.Save(Response.OutputStream, ImageType.GIF).

I am confident that the transparency is working properly because if I save
the created image to the local hard disk and then view it in a web page or an
image editor, the transparency is correct. I can also view the transparency
on-the-fly in a Windows.Forms application.

Yet, when I render the image on-the-fly to the Response.OutputStream, I lose
the transparency and the background color is displayed in the page.

Has anyone got any ideas or experience in rendering transparent GIFs this way?

Thanks,
--
Dale Preston
MCAD C#
MCSE, MCDBA
Oct 20 '06 #1
4 10185
Hello Dale,

From your description, you've programmatically create an transparent gif
image and flush it into ASP.NET page's response stream. However, you found
the output image lose the transparency, correct?

Based on my understanding, it is likely that the bits save into the
response stream is different from the expected transparent gif's binary
bits. I suggest you test through the following means:

1. first use your code to generate the gif and save it into a disk file(gif
file), make sure that the gif file is working as transparent one.

2. use ASP.NET code to write the gif file into response stream as below:

===============
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "image/gif"
Response.WriteFile("D:\temp\web_temp\images\duglog obigtextcolor.gif")

Response.End()

End Sub
===============

based on my test, the above code can correctly flush a correct transparent
gif out to client-side. If the above test also return a non-transparent
one, it seems the generated gif has some bits get corrupted.

Please feel free to let me know if you have any other finding or anything I
missed.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 20 '06 #2
Thanks, Steven. I was afraid you were going to say that. Our web
infrastructure policies don't generally allow web apps to write to the local
disk so that's going to be a problem. I may have to look for another
alternative.

The goal was to present an error message in a text bubble with the bubble
hook pointing to the form field with the improper value. The transparent GIF
seemed like just the ticket.

Do you have any other suggestions or know of articles or examples of
alternative methods for displaying text in a bubble like that on-the-fly?

I built my code following the examples in KB #319061 and
http://www.bobpowell.net/giftransparency.htm. Do you know if I would have
the same problem with a transparent PNG? If a PNG is a possibility, do you
know of any documentation on how to set the transparency in a PNG using .Net?
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Steven Cheng[MSFT]" wrote:
Hello Dale,

From your description, you've programmatically create an transparent gif
image and flush it into ASP.NET page's response stream. However, you found
the output image lose the transparency, correct?

Based on my understanding, it is likely that the bits save into the
response stream is different from the expected transparent gif's binary
bits. I suggest you test through the following means:

1. first use your code to generate the gif and save it into a disk file(gif
file), make sure that the gif file is working as transparent one.

2. use ASP.NET code to write the gif file into response stream as below:

===============
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "image/gif"
Response.WriteFile("D:\temp\web_temp\images\duglog obigtextcolor.gif")

Response.End()

End Sub
===============

based on my test, the above code can correctly flush a correct transparent
gif out to client-side. If the above test also return a non-transparent
one, it seems the generated gif has some bits get corrupted.

Please feel free to let me know if you have any other finding or anything I
missed.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 20 '06 #3
Just FYI, Steven.

I was able to resolve my problem and, hopefully make my solution more robust
than it may have otherwise been.

The problem was that the Bitmap object I was drawing on using the Graphics
class seems to corrupt the palette by duplicating a single palette entry
which was, coincidentally, the transparent color.

While I was aware of the duplication, I was skipping the first occurrence
because no pixels pointed to it. The second occurrence was where all the
transparent pixels pointed and that is the entry I set the alpha to 0 on.
This issue did not cause any problems in Windows.Forms, in Paint Shop Pro, in
Microsoft Image Composer, or if I saved to disk and then opened the saved
file in a web page.

For some reason, though, it did create a problem when saving to the
Response.OutputStream because the method requires re-assigning the ImageType.
There should be an overload of the Save method that writes to a Stream
without having to pass the ImageType just as there is an overload that saves
to a file.

The bottom line is, I re-wrote my code to detect duplicate entries in the
palette, then modify all pixels that pointed to any of the duplicates so that
they point to the first occurrence of the color, and then modify all of the
remaining duplicate palette entries so that they are unique. With this done,
I was able to save my image to the Response.OutputStream with the
transparency working as expected.

Thanks again for your help.

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Dale" wrote:
Thanks, Steven. I was afraid you were going to say that. Our web
infrastructure policies don't generally allow web apps to write to the local
disk so that's going to be a problem. I may have to look for another
alternative.

The goal was to present an error message in a text bubble with the bubble
hook pointing to the form field with the improper value. The transparent GIF
seemed like just the ticket.

Do you have any other suggestions or know of articles or examples of
alternative methods for displaying text in a bubble like that on-the-fly?

I built my code following the examples in KB #319061 and
http://www.bobpowell.net/giftransparency.htm. Do you know if I would have
the same problem with a transparent PNG? If a PNG is a possibility, do you
know of any documentation on how to set the transparency in a PNG using .Net?
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Steven Cheng[MSFT]" wrote:
Hello Dale,

From your description, you've programmatically create an transparent gif
image and flush it into ASP.NET page's response stream. However, you found
the output image lose the transparency, correct?

Based on my understanding, it is likely that the bits save into the
response stream is different from the expected transparent gif's binary
bits. I suggest you test through the following means:

1. first use your code to generate the gif and save it into a disk file(gif
file), make sure that the gif file is working as transparent one.

2. use ASP.NET code to write the gif file into response stream as below:

===============
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "image/gif"
Response.WriteFile("D:\temp\web_temp\images\duglog obigtextcolor.gif")

Response.End()

End Sub
===============

based on my test, the above code can correctly flush a correct transparent
gif out to client-side. If the above test also return a non-transparent
one, it seems the generated gif has some bits get corrupted.

Please feel free to let me know if you have any other finding or anything I
missed.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Oct 21 '06 #4
Hi Dale,

Thanks for your followup.

I'm glad that you've figured out the problem and found a workable solution.

As always, welcome to post here when you need any help from us.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to...
3
by: anastasia | last post by:
I get an out of memory exception when attempting to excecute the following code: original = System.Drawing.Image.FromFile(file.FileName,true); I ONLY get this exception when the file is in the...
0
by: eruess | last post by:
Here's the scenario: I've got a whole bunch (for the sake of argument, let's say thousands) of different little 32x14 .png files that act as buttons all over a very large website. Each button...
0
by: John via .NET 247 | last post by:
Hi, I'm using the System.Drawing.Bitmap namespace to load an image,and the RotateNoneFlipY method to flip that image before saving.However I have noticed that the saved image appears cropped...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
0
by: MasterOfTheDark | last post by:
This one's a hairy one to explain. What I've got is a class called "VistaGroupBox" that I put some nice-looking Vista-style gradients in the background and made to look like the ribbon categories...
0
by: vladimir.knobel | last post by:
Hi everyone, I'm working in a MCMS 2002 site and for a template I need to create images on the fly. The image format of choice is PNG because this images had to have a transparent background...
2
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

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.