By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,322 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

Merging images together

P: n/a
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.

Oct 17 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Oct 17, 7:06 am, toby.k.w...@googlemail.com wrote:
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

Oct 17 '07 #2

P: n/a
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?

Oct 18 '07 #3

P: n/a
On Oct 18, 7:58 am, toby.k.w...@googlemail.com wrote:
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

Oct 18 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.