Merging images together

T

toby.k.webb

Hi all,

I have two images that I would like to merge together similar to a
watermark (one becomes semi-transparent).

Is there a way to do this in vb.net?

Thanks.
 
R

rowe_newsgroups

Hi all,

I have two images that I would like to merge together similar to a
watermark (one becomes semi-transparent).

Is there a way to do this in vb.net?

Thanks.

Off the top of my head:

1) Create a new bitmap object that represents the watermark image.
2) Loop through the bitmap's pixel and use SetColor and
Color.FromArgb() to set the alpha level of the pixel
3) Load the bitmap as normal.

Thanks,

Seth Rowe
 
T

toby.k.webb

Seth,

Thanks for your reply. I had tried this but it is really slow, and
wondered if there was a control or another way of doing this.

The code I have for your example is:

Dim clr As Color
For py As Integer = 0 To bm.Height - 1
For px As Integer = 0 To bm.Width - 1
clr = bm.GetPixel(px, py)
If clr <> Color.White Then
bm.SetPixel(px, py, Color.FromArgb(ALPHA, clr.R, clr.G,
clr.B))
End If
Next px
Next py

' Set the watermark's transparent color.
bm.MakeTransparent(bm.GetPixel(0, 0))

' Copy onto the result image.
Dim gr As Graphics = Graphics.FromImage(PictureBox1.Image)
gr.DrawImage(bm, 0, 0)



Is there any way to speed this up?
 
R

rowe_newsgroups

Seth,

Thanks for your reply. I had tried this but it is really slow, and
wondered if there was a control or another way of doing this.

The code I have for your example is:

Dim clr As Color
For py As Integer = 0 To bm.Height - 1
For px As Integer = 0 To bm.Width - 1
clr = bm.GetPixel(px, py)
If clr <> Color.White Then
bm.SetPixel(px, py, Color.FromArgb(ALPHA, clr.R, clr.G,
clr.B))
End If
Next px
Next py

' Set the watermark's transparent color.
bm.MakeTransparent(bm.GetPixel(0, 0))

' Copy onto the result image.
Dim gr As Graphics = Graphics.FromImage(PictureBox1.Image)
gr.DrawImage(bm, 0, 0)

Is there any way to speed this up?

I'm not to sure about how to speed up your code. You may want to post
the code in the microsoft.public.dotnet.framework.drawing newsgroups,
as they will most likely be able to help you more. Also, you may see
if you can get the source for Paint .Net, it's a terrific program that
features variable transparency layers and I believe it's open source.
Taking a look at their algorithm might give you some ideas.

Thanks,

Seth Rowe
 

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