Link to home
Start Free TrialLog in
Avatar of Dumdidum
Dumdidum

asked on

Get a rectangle from a bitmap and save to file

Hello

I want to select a part of a bitmap (for example rectangle from 40,40 to 100,100 and save this as new bitmap to a file...

Is this possible?

Thanks

Sven
Avatar of S-Twilley
S-Twilley

Well you could use BitBlt....  I'll see if there is a VB.NET equiv'
   Const SRCCOPY As Integer = &HCC0020
    Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer




    Dim BitmapSrc As New Bitmap("C:\X.bmp")
    Dim BitmapSrcGraphic As Graphics
    Dim BitmapSrcHDC As IntPtr
    BitmapSrcGraphic = BitmapSrcGraphic.FromImage(BitmapSrcObj)

    Dim BitmapDest As New Bitmap(320, 240)
    Dim BitmapDestGraphic As Graphics
    Dim BitmapDestHDC As IntPtr
    BitmapDestGraphic = BitmapDestGraphic.FromImage(BitmapDestObj)

    Dim BltReturn As Integer


    BltReturn = BitBlt(BitmapDestHDC.ToInt32, 0, 0, 320, 240, BitmapSrcHDC.ToInt32, 5, 5, SRCCOPY)

=======

Non tested... let me know of problems
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial