CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Feb 2008
    Posts
    12

    Stretchblt in .NET

    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.

    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
    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.
    Last edited by vitaloverdose; September 29th, 2010 at 02:31 PM. Reason: better explained

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured