Possible bug in System.Drawing.Graphics when dealing with multipage TIFFs and transparency

N

news.microsoft.com

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 create a form, a button
(Button1) and an Picture Box (picBox).
"watermark.jpg" is any jpg image, "beispiel.tif" is a multipage TIFF image
with the white background, which will turn to transparent.
The most important thing here is that the TIFF image should be a multipage
type (multiple images in a single *.TIF file).
You can download a multipage TIFF for testing from:
http://www.patent-inf.tu-ilmenau.de/patonline/beispiel.tif

The bug(?) is:
In the code bellow the line:
imgTop.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, 4)
is doing the same as
imgTop.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, 0)
That means, it does not select the page 4. It selects the first page
instead, no matter we specified "4".

My guess is that this odd behaviour has something to do with the
transparency of the image, because when the line:
imgTop.MakeTransparent(Color.White) is commented, the thing works, the
desired page is selected, but there is no transparency and the background
image is not visible.


The source code:
''''''''''''''''''''''''''''''''''''''
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim imgBack As New Bitmap("d:\temp\watermark.jpg")
Dim imgTop As Bitmap = New Bitmap("d:\temp\beispiel.tif")
Dim g As Graphics = Graphics.FromImage(imgBack)

Dim rect As New Rectangle(0, 0, imgBack.Width, imgBack.Height)
imgTop.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page,4)
imgTop.MakeTransparent(Color.White)
g.DrawImage(imgTop, rect, 0, 0, imgTop.Width, _
imgTop.Height,GraphicsUnit.Pixel)
picBox.Image = imgBack
End Sub
'''''''''''''''''''''''''''''''''''''

How to overcome this issue? Is there another approach to get a transparent
multipage TIFF?

Thanks,
BB
 
J

John Eikanger [MSFT]

Hi, BB

I notice that you posted the same message in
microsoft.public.dotnet.drawing. I have received a commitment from the GDI
tech lead to respond to you there.

Posting multiple messages in this way is called multi-posting, which is
considered poor manners in the newsgroups and will get you flamed if some
people notice. This is because an answer to one post is not available in
the other. If I answer your question in one thread and it was already
answered in another thread, I've wasted my time. The preferred technique
is called crossposting, which puts linked copies of the same post in
multiple newsgroups.. You can crosspost using Outlook Express or the MSDN
Web interface by explicitly typing the names of the groups (separated by a
comma or a semi-colon) in the Newsgroup box that appears when you post.

Example: microsoft.public.vb.com;microsoft.public.vb.database.ado etc.

HTH,

John Eikanger
Microsoft Visual Basic Team

This posting is provided “AS IS” with no warranties, and confers no rights.
(c) 2003 Microsoft Corporation. All rights reserved.
--------------------
| From: "news.microsoft.com" <[email protected]>
| Subject: Possible bug in System.Drawing.Graphics when dealing with
multipage TIFFs and transparency
| Date: Tue, 21 Oct 2003 10:25:09 +0200
| Lines: 53
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.general
| NNTP-Posting-Host: 213.202.70.114
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:112641
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| 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 create a form, a button
| (Button1) and an Picture Box (picBox).
| "watermark.jpg" is any jpg image, "beispiel.tif" is a multipage TIFF image
| with the white background, which will turn to transparent.
| The most important thing here is that the TIFF image should be a multipage
| type (multiple images in a single *.TIF file).
| You can download a multipage TIFF for testing from:
| http://www.patent-inf.tu-ilmenau.de/patonline/beispiel.tif
|
| The bug(?) is:
| In the code bellow the line:
| imgTop.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, 4)
| is doing the same as
| imgTop.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, 0)
| That means, it does not select the page 4. It selects the first page
| instead, no matter we specified "4".
|
| My guess is that this odd behaviour has something to do with the
| transparency of the image, because when the line:
| imgTop.MakeTransparent(Color.White) is commented, the thing works, the
| desired page is selected, but there is no transparency and the background
| image is not visible.
|
|
| The source code:
| ''''''''''''''''''''''''''''''''''''''
| Private Sub Button1_Click(ByVal sender As System.Object, _
| ByVal e As System.EventArgs) Handles Button1.Click
| Dim imgBack As New Bitmap("d:\temp\watermark.jpg")
| Dim imgTop As Bitmap = New Bitmap("d:\temp\beispiel.tif")
| Dim g As Graphics = Graphics.FromImage(imgBack)
|
| Dim rect As New Rectangle(0, 0, imgBack.Width, imgBack.Height)
| imgTop.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page,4)
| imgTop.MakeTransparent(Color.White)
| g.DrawImage(imgTop, rect, 0, 0, imgTop.Width, _
| imgTop.Height,GraphicsUnit.Pixel)
| picBox.Image = imgBack
| End Sub
| '''''''''''''''''''''''''''''''''''''
|
| How to overcome this issue? Is there another approach to get a transparent
| multipage TIFF?
|
| Thanks,
| BB
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top