הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Saturday, March 15, 2014 2:04 AM
Hello everyone,
I have a problem in merging two images.
a.png size is 320 x 480 (frame). The transparency start at 50 x 50.
b.png size is 270 x 430 (take from camera).
So I merge two images and saved (the picture took from camera is in the frame). However, saved image size is 270 x 430 (not display all frame) and I can not get full size(320 x 480) (i can not get full frame with picture is in the frame)
How do I make it correct?
here is my code
Dim imgOverlay As Bitmap = Image.FromFile("a.png")
Dim imgBackground As Bitmap = Image.FromFile("b.png")
Dim g As Graphics = Graphics.FromImage(imgBackground)
imgOverlay.MakeTransparent(Color.White)
g.DrawImage(imgOverlay, 0, 0)
g.Dispose()
imgBackground.Save("c.png")
help me guys
All replies (3)
Saturday, March 15, 2014 2:36 AM ✅Answered | 2 votes
Hi,
You are drawing the larger image on top of the smaller image and then saving the smaller image which is 270 x 430. If you want the size to be of the larger image 320 x 480 then you can try creating a new empty bitmap the size of the larger image and draw the smaller image in the center of the new empty bitmap and then draw your larger overlay image on top of that. Then you can save the new bitmap which has both images drawn on it.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim imgOverlay As Bitmap = CType(Image.FromFile("a.png"), Bitmap)
Dim imgBackground As Bitmap = CType(Image.FromFile("b.png"), Bitmap)
Dim tmp As New Bitmap(imgOverlay.Width, imgOverlay.Height) 'New empty bitmap the size of the larger image
Dim g As Graphics = Graphics.FromImage(tmp)
g.DrawImage(imgBackground, CInt((imgOverlay.Width - imgBackground.Width) / 2), CInt((imgOverlay.Height - imgBackground.Height) / 2))
imgOverlay.MakeTransparent(Color.White)
g.DrawImage(imgOverlay, 0, 0)
g.Dispose()
tmp.Save("c.png", Imaging.ImageFormat.Png)
tmp.Dispose()
End Sub
You could also draw the smaller image onto the empty bitmap the same size as the empty bitmap but, that may stretch your camera image out of proportion. You can do that by changing this line
g.DrawImage(imgBackground, 0, 0, imgOverlay.Width, imgOverlay.Height)
Monday, March 17, 2014 8:52 AM
Thank
Monday, March 17, 2014 10:33 AM
Thank
Your Welcome. :)
Please don`t forget to mark the post that answered your question as the answer. It makes it easier for others to find the answer when searching for an answer to the same problem. Thanks.