Minh Tuan Pham
Minh Tuan Pham

Reputation: 33

How to crop bitmap in AutoIt?

I have this code below to print a bitmap image, but I don't want to print the full size of the handle. Is it possible to print only a square or crop the bitmap image after print? I am using AutoIt.

This is the first time I posted a question, please forgive any mistakes.

$hDDC = _WinAPI_GetDC($hWnd)

$hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight)
$hCDC = _WinAPI_CreateCompatibleDC($hDDC)

_WinAPI_SelectObject($hCDC, $hBMP)

DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", 0)

_WinAPI_DeleteDC($hCDC)
_WinAPI_ReleaseDC($hWnd, $hDDC)

Upvotes: 2

Views: 828

Answers (1)

Bookeater
Bookeater

Reputation: 474

You can use _GDIPlus_BitmapCloneArea to get a rectangle from a bitmap.

You'll need to include the library first:

 #include <GDIPlus.au3>

To crop:

 $hClone = _GDIPlus_BitmapCloneArea ( $hBitmap, $nLeft, $nTop, $nWidth, $nHeight [, $iFormat = 0x00021808] )

A slightly useful example:
https://www.autoitscript.com/forum/topic/164820-crop-an-image-from-file/

Upvotes: 1

Related Questions