Phaser Posted October 7, 2014 Share Posted October 7, 2014 Hi guys I want to, after finding my coordinates, crop an image from file, I have already passed a screencapture through GDIPlus and performed some colour changes to the pixels, now I need to find those pixels to get my coords to crop, so I want to load the result.bmp from file then crop to my coordinates, it wont work! $hBitmap = "result.bmp";_ScreenCapture_Capture("") $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) I understand from the help file that screencapture without a file name creates a HBITMAP so I can I get around this for _GDIPlus_BitmapCloneArea to work? changing FromHBITMAP to FromFILE doesn't work either, any suggestions? Link to comment Share on other sites More sharing options...
UEZ Posted October 7, 2014 Share Posted October 7, 2014 _ScreenCapture_Capture() creates a GDI bitmap which needs to be converted first if you want to work with it using GDI+.First convert it using _GDIPlus_BitmapCreateFromHBITMAP() then proceed to work with GDI+.I assume you included only #include <ScreenCapture.au3>. Use _GDIPlus_Startup() and when closing _GDIPlus_Shutdown(). Otherwise GDI+ functions are not ready for usage.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 More sharing options...
Phaser Posted October 7, 2014 Author Share Posted October 7, 2014 Hi UEZ, thanks for the reply _GDIPlus_BitmapCreateFromHBITMAP() is the problem as it needs a HBITMAP I want to use an image already in the script folder, heres what I have #include <GDIPlus.au3> #include <ScreenCapture.au3> Example() Func Example() Local $hBitmap, $hClone, $hImage, $iX, $iY ; Initialize GDI+ library _GDIPlus_Startup() ; Capture 32 bit bitmap $hBitmap = "result.bmp" $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) ; Create 24 bit bitmap clone $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX/2, $iY/2, $GDIP_PXF24RGB) ; Save bitmap to file _GDIPlus_ImageSaveToFile($hClone, @ScriptDir & "\GDIPlus_Image.bmp") ; Clean up resources _GDIPlus_ImageDispose($hClone) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "\GDIPlus_Image.bmp") EndFunc ;==>Example result.bmp is an image I have already worked on using GDI+ functions after all the work on an original file I save it as result.bmp, I now want to crop result.bmp removing all the white to the left, right, top and bottom so I am left with a smaller rectangle with the word in it, the word could be anywhere in the file, I already have decided how I am going to get the coordinates to crop I just can't load the file to run it through _GDIPlus_BitmapCloneArea as it want a HBITMAP not an image already available. I hope you understand what I am wanting to do. result.bmp Link to comment Share on other sites More sharing options...
UEZ Posted October 7, 2014 Share Posted October 7, 2014 (edited) Try this: #include <GDIPlus.au3> Example() Func Example() Local $hBitmap, $hClone, $hImage, $iX, $iY ; Initialize GDI+ library _GDIPlus_Startup() ; Capture 32 bit bitmap $hImage = _GDIPlus_ImageLoadFromFile("result.bmp") ; Create 24 bit bitmap clone $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX/2, $iY/2, $GDIP_PXF24RGB) ; Save bitmap to file _GDIPlus_ImageSaveToFile($hClone, @ScriptDir & "\GDIPlus_Image.bmp") ; Clean up resources _GDIPlus_ImageDispose($hClone) _GDIPlus_ImageDispose($hImage) ; Shut down GDI+ library _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "\GDIPlus_Image.bmp") EndFunc ;==>Example This makes no sense: $hBitmap = "result.bmp" $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) How can a string be a bitmap? Br, UEZ Edited October 7, 2014 by UEZ robertocm and pixelsearch 2 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 More sharing options...
Phaser Posted October 8, 2014 Author Share Posted October 8, 2014 Hi UEZ thanks again, that just returns an empty image? Link to comment Share on other sites More sharing options...
UEZ Posted October 8, 2014 Share Posted October 8, 2014 You have to add the correct path to the bitmap $hImage = _GDIPlus_ImageLoadFromFile("result.bmp") ;enter the correct path here! 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 More sharing options...
Phaser Posted October 8, 2014 Author Share Posted October 8, 2014 Nope I was wrong, _GDIPlus_BitmapCloneArea(left, top, WIDTH, HEIGHT, ....24 etc) I was using the wrong coords, I was working with bottom, right as you would with screencapture etcbut clone wants the start coords then width and height. Thanks UEZ it works as expected. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now