Jump to content

Crop HBITMAP?


Recommended Posts

Hi

Is it possible to crop a HBITMAP directly? I got it working by using GDI+ by converting to bitmap, copy wanted part, then convert back to hbitmp.

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

_GDIPlus_Startup ()

$begin = TimerInit()    ; Test, screenshot direct to hbitmap
Local $hHBMP = _ScreenCapture_Capture('',0,0,@DesktopWidth,@DesktopHeight,False)
ConsoleWrite("Creating _ScreenCapture_Capture hbitmap Desktop screenshot took " & TimerDiff($begin) & " milliseconds"& @LF)

$begin = TimerInit()    ; Test, Crop from hbitmap
Local $hBMP= _GDIPlus_BitmapCreateFromHBITMAP($hHBMP)
Local $hBMP_Cropped = _GDIPlus_BitmapCloneArea($hBMP, 0, 0, 110, 110)
Local $hHBMP_Cropped = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP_Cropped)
;_GDIPlus_ImageSaveToFile($hBMP_Cropped, $BMP3)
ConsoleWrite("Creating cropped hbitmap Desktop screenshot took " & TimerDiff($begin) & " milliseconds"& @LF)
Link to comment
Share on other sites

Maybe

_ScreenCapture_Capture(@ScriptDir & "\Cropped.jpg", 0,0,110, 110,False)

 

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

No, you misunderstand. I want to create a "master" screenshot, directly to hbitmap. Later in my program i will use different parts from the master screenshot. The line with save cropped image to file was just for debug.

Edit; my example does what i want, but is it neccessary to convert hbitmap to bitmap to do cropping?

Edited by Geir1983
Link to comment
Share on other sites

It should be possible to crop with GDI but I assume it is much more complicated to do it rather with the method you have posted.
 
Why you are converting it back to HBitmap ($hHBMP_Cropped) again?

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...