Sign in to follow this  
Followers 0
Geir1983

Crop HBITMAP?

5 posts in this topic

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)

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

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

Share this post


Link to post
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Ok ill just stick with that method then. I thought it might be an faster way to do it. I convert back to hbitmap because that is the input for other functions i use.

Share this post


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
Sign in to follow this  
Followers 0