Results 1 to 4 of 4

Thread: How to copy image form file to picturbox with Bitblt in VB2013?

  1. #1

    Thread Starter
    New Member Taro's Avatar
    Join Date
    Feb 2014
    Posts
    11

    How to copy image form file to picturbox with Bitblt in VB2013?

    Hi,

    I'm very new for VB.net since I use VB6 for long time. Now, consider to move to .net. The problem is I know very less thing about it. After few months with many trial. I need someone to help me to solve my problem for use Win32 API with VB2013.

    Yes, it have any new way to deal with image. But not only Standard API I need to work with. So, Bitblt is a simple way to learn how to copy image by API withing VB2013.

    Please see my snipped code below
    Code:
    Imports System.Runtime.InteropServices
    
    Declare Auto Function BitBlt Lib "GDI32.DLL" ( _
            ByVal hdcDest As IntPtr, _
            ByVal nXDest As Integer, _
            ByVal nYDest As Integer, _
            ByVal nWidth As Integer, _
            ByVal nHeight As Integer, _
            ByVal hdcSrc As IntPtr, _
            ByVal nXSrc As Integer, _
            ByVal nYSrc As Integer, _
            ByVal dwRop As Int32) As Integer
    
    Public Sub InitialImage(ByVal ImageFileName As String)
    	Dim ImageWidth As Integer
    	Dim ImageHeight As Integer
    
    	Dim tempImage As Bitmap = Image.FromFile(ImageFileName)
    
    	ImageWidth = tempImage.Width
    	ImageHeight = tempImage.Height
    
    	Dim tempSrcGx As Graphics = Graphics.FromImage(tempImage)
    
    	Dim tempDestBitmap As Bitmap = New Bitmap(ImageWidth, ImageHeight, tempSrcGx)
    	Dim tempDestGx As Graphics = Graphics.FromImage(tempDestBitmap)
    
    	Dim ret As Integer = 0
    
    	Dim SrcHDC As IntPtr = tempSrcGx.GetHdc
    	Dim DestHDC As IntPtr = tempDestGx.GetHdc
    
    	ret = BitBlt(DestHDC, 0, 0, ImageWidth, ImageHeight, SrcHDC, 0, 0, 13369376)
    
    	MemoryImage.Image = tempDestBitmap.Clone
    	MemoryImage.Size = New Size(MemoryImage.Image.Size)
    	MemoryImage.Refresh()
    End Sub
    Note that MemoryImage is my on screen picturebox. The code not have any runtime error. But what I get all the time is total black image. I try with many suggested code around the world already. Still not success. So tired now. Please help.

    Taro

  2. #2

    Re: How to copy image form file to picturbox with Bitblt in VB2013?

    UPDATE* I accidentally pasted the wrong article for image cropping in winforms. Fixed...


    Try and think of win32 api as something you should start moving away from, except for extremely special circumstances.

    Are you cropping an image?
    Cropping and Scaling Images in GDI+

    Are you pasting a cropped image into another image?

    Graphics.DrawImage

    Note* Please look at all of the overloads for graphics.drawimage
    Last edited by paulishak; Jan 17th, 2015 at 01:06 PM. Reason: Wrong article

  3. #3

    Thread Starter
    New Member Taro's Avatar
    Join Date
    Feb 2014
    Posts
    11

    Re: How to copy image form file to picturbox with Bitblt in VB2013?

    Thank you so much paulishak.

    However, I have custom dll to deal with, hard to move away from its. So, the better way to learn about image in picturebox. It's the Bitblt function.

    I'm surprise that even I copy work code from sample then paste into my project. It's also not working. Or what happen to my project?

    Anyone can help?

  4. #4

    Thread Starter
    New Member Taro's Avatar
    Join Date
    Feb 2014
    Posts
    11

    Re: How to copy image form file to picturbox with Bitblt in VB2013?

    Anyone Help...Please

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