Jump to content

Display Clipped Image Double The Size of Original


Recommended Posts

Hi all,

I'm puzzled, I can't seem to get the clip to display twice it's original size. Here is the code I put together:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>

Example()

Func Example()
   $x1=0
   $y1=0
   $x2=100
   $y2=100
   $w=$x2-$x1
   $h=$y2-$y1

   GUICreate("Test", 600, 600)
   $hImagePic=GUICtrlCreatePic("", 10 + 5 , 70 + 5, $w*2, $h*2) ;x,y,w,h
   GUISetState(@SW_SHOW)

   _GDIPlus_Startup() ; Initialize GDI+ library
   $hOrigSS = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\1.jpg")     ; Capture 32 bit bitmap and return a bitmap image object
   $hClip = _GDIPlus_BitmapCloneArea($hOrigSS,  $x1, $y1, $w, $h) ;Clip out area of bitmap object; left,top,width,height

   ;What am I missing?

   $hResize = _WinAPI_AdjustBitmap ( $hClip, $w*2, $h*2) ;Enlarge width & height
   $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hResize) ; Create bitmap object from bitmap handle
   $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($hImagePic)) ; Get the winhandle of the control holding the image and create Graphics Object
   _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0) ;Paste the picture into the control holding the image

   _GDIPlus_GraphicsDispose($hGraphic) ; Clean up resources
   _GDIPlus_BitmapDispose($hBitmap)
   _WinAPI_DeleteObject($hOrigSS)
   _GDIPlus_Shutdown() ; Shut down GDI+ library

       While 1
           Switch GUIGetMsg()
               Case $GUI_EVENT_CLOSE
                   ExitLoop
           EndSwitch
       WEnd
   GUIDelete()
EndFunc ;==>Example

 

Edited by NassauSky
Link to post
Share on other sites
; like this
$hClip = _GDIPlus_BitmapCloneArea($hOrigSS,  $x1, $y1, $w, $h) ; Clip out area of bitmap object; left,top,width,height
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hClip) ; Create bitmap handle from bitmap object
$hResize = _WinAPI_AdjustBitmap($hBMP, $w*2, $h*2) ; Enlarge width & height
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hResize) ; Create bitmap object from bitmap handle
$hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($hImagePic)) ; Get the winhandle of the control holding the image and create Graphics Object
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0) ; Paste the picture into the control holding the image

; or like this
$hClip = _GDIPlus_BitmapCloneArea($hOrigSS,  $x1, $y1, $w, $h) ; Clip out area of bitmap object; left,top,width,height
$hResize = _GDIPlus_ImageScale($hClip, 2, 2) ; Enlarge width & height
$hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($hImagePic)) ; Get the winhandle of the control holding the image and create Graphics Object
_GDIPlus_GraphicsDrawImage($hGraphic, $hResize, 0, 0) ; Paste the picture into the control holding the image

 

Edited by InnI
Link to post
Share on other sites

Thanks @InnI

Better answer than I expected. First you gave 2 solutions and better yet that you marked my comments so I knew what I did wrong.  

Using my longer way I had to revert it back to  a bitmap object from a handle but I do like your 2nd option better.

 

Thanks again!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...