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/...e/beispiel.tif
The bug(?) is:
In the code bellow the line:
imgTop.SelectActiveFrame(System.Drawing.Imaging.Fr ameDimension.Page, 4)
is doing the same as
imgTop.SelectActiveFrame(System.Drawing.Imaging.Fr ameDimension.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.Fr ameDimension.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