Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Merge two pictures in VB.NET

Posted on 2003-04-01
Medium Priority
Last Modified: 2007-12-19
I have three pictureboxes. How to combine two pictures from two pictureboxes to third one...so that first picture is behind the second?
I need to save the third (combined) picture in database... (i know how to do this)

Thank you in advance.
Question by:djcybex
  • 2
LVL 28

Accepted Solution

iboutchkine earned 320 total points
ID: 8246099
This code will overlay 1 bmp over another
Bitmap Circle = (Bitmap)Image.FromFile(@"c:\circle.bmp");
     Bitmap MergedBMP = (Bitmap)Image.FromFile(@"c:\cross.bmp");
     Graphics g = Graphics.FromImage(Circle);

     pictureBox1.Image = Circle;

Author Comment

ID: 8247136
Thank you!

can you please suggest how to center the front picture to the one in the back?

i know you can set cordinates in

but pictures are diferent sizes...
and also DrawImage makes picture smaller than original..why is that?
LVL 28

Expert Comment

ID: 8247333
Try either to resize image

Private Sub ResizeImage()
     Dim filename As String = "C:\windows\web\wallpaper\wind.jpg"
     Dim photo As System.Drawing.Bitmap = New System.Drawing.Bitmap(filename)
     'Resize to medium
     Dim w As Integer = 200
     Dim h As Integer = 200
     Dim medium As New System.Drawing.Bitmap(w, h)
     Dim mG As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(medium)
     mG.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed
     mG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic
     mG.DrawImage(photo, 0, 0, w, h)
     medium.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg)
End Sub

or stretch it to the picbox size
 picImage.SizeMode = PictureBoxSizeMode.StretchImage

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Integration Management Part 2
Loops Section Overview

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question