Hi im new to .net 2010 and im having a problem with using stretchblt.
Im trying to load in a BMP , copy part of that image and paste it back in the same image but stretched out. Then display and save the result.
First i pieced some code together that grabbed an image from a picture box , coppied part of it and pasted it back into the image. This worked fine except that it also copied anythingthat was sat on top of the image in the picture box as well as the image data.
So ive been trying to load in the bitmap from a file rather than take the one displayed in the picture box but nothing seems to work.Code:
Private Sub but_Render_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Render.Click
pbx_main.Image = CType(RenderImage(pbx_main), Bitmap).Clone
End Sub
Private Function RenderImage(ByVal src As PictureBox) As Bitmap
'Create bitmap from image file
Dim srcBmp As New Bitmap(LoadedImageFileName)
'Create a Graphics object in memory from that bitmap
Dim srcMem As Graphics = Graphics.FromImage(srcBmp)
'Get a Graphics Object from picture box
Dim srcPic As Graphics = src.CreateGraphics
'get the IntPtr's of the graphics
Dim HDC1 As IntPtr = srcPic.GetHdc
'get the IntPtr's of the graphics
Dim HDC2 As IntPtr = srcMem.GetHdc
'StretchBlt the picture
StretchBlt(HDC2, 200, 200, 200, 200, HDC1, 50, 50, 50, 50, TernaryRasterOperations.SRCCOPY)
'Clone the bitmap so we can dispose this one
RenderImage = srcBmp.Clone()
'Clean Up
srcPic.ReleaseHdc(HDC1)
srcMem.ReleaseHdc(HDC2)
srcPic.Dispose()
srcMem.Dispose()
srcBmp.Dispose()
End Function

