lesolutionneur Posted January 15, 2012 Posted January 15, 2012 Hi,I want to cut an image :I've seen that gdiplus can do it.Basically : I've that is a 400*519 image and I want cut it to that is 400*400.So, I use this code to do what I want :#include <GDIPlus.au3> Func _ImageCut($hImage, $iX, $iY, $iWidth, $iHeight) Local $iImageWidth, $iImageHeight, $hOldGC, $hNewGC, $hOldBmp, $hNewBmp $iImageWidth = _GDIPlus_ImageGetWidth($hImage) $iImageHeight = _GDIPlus_ImageGetHeight($hImage) ; Create New image $hNewBmp = _GDIPlus_BitmapCloneArea($hImage, $iX, $iY, $iWidth, $iHeight, $GDIP_PXF32ARGB); Get Piece of Bmp $hNewGC = _GDIPlus_ImageGetGraphicsContext($hNewBmp); Get GC from new created Bmp _GDIPlus_GraphicsDispose($hNewGC) Return $hNewBmp EndFunc ;==>_ImageCut $gdi_pngSrc = @ScriptDir & "\AlbumArt.jpg" $gdi_hImage = _GDIPlus_ImageLoadFromFile($gdi_pngSrc) $gdi_resized_image = _ImageCut($gdi_hImage, 0, 0, 400, 400) ;_GDIPlus_ImageSaveToFile($gdi_resized_image, @ScriptDir & "\AlbumArt.jpg")But I obtain the following error :"Line 957 (File "C:\Users\ls\Desktop\autoit-v3.3.8\Include\GDIPlus.au3"):For $iI = 1 To $aEncoders[0][0]For $iI = 1 To $aEncoders^ ERRORError: Subscript used with non-Array variable."How can I fix it ? Did I something wrong ?PS: don't say that colonel reyel sucks
UEZ Posted January 15, 2012 Posted January 15, 2012 You forgot _GDIPlus_Startup() #include <GDIPlus.au3> Func _ImageCut($hImage, $iX, $iY, $iWidth, $iHeight) Local $iImageWidth, $iImageHeight, $hOldGC, $hNewGC, $hOldBmp, $hNewBmp $iImageWidth = _GDIPlus_ImageGetWidth($hImage) $iImageHeight = _GDIPlus_ImageGetHeight($hImage) ; Create New image $hNewBmp = _GDIPlus_BitmapCloneArea($hImage, $iX, $iY, $iWidth, $iHeight, $GDIP_PXF32ARGB); Get Piece of Bmp ;~ $hNewGC = _GDIPlus_ImageGetGraphicsContext($hNewBmp); Get GC from new created Bmp ;~ _GDIPlus_GraphicsDispose($hNewGC) Return $hNewBmp EndFunc ;==>_ImageCut _GDIPlus_Startup() $gdi_pngSrc = @ScriptDir & "853930reyel1.png" $gdi_hImage = _GDIPlus_ImageLoadFromFile($gdi_pngSrc) $gdi_resized_image = _ImageCut($gdi_hImage, 0, 0, 400, 400) _GDIPlus_ImageSaveToFile($gdi_resized_image, @ScriptDir & "AlbumArt.jpg") _GDIPlus_ImageDispose($gdi_hImage) _GDIPlus_BitmapDispose($gdi_resized_image) _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "AlbumArt.jpg") 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
lesolutionneur Posted January 15, 2012 Author Posted January 15, 2012 (edited) And does it work for you ? A women of the French forum give me this solution : #Include <GDIPlus.au3> _GDIPlus_Startup() $bmp = _GDIPlus_ImageLoadFromFile("original.jpg") $bmp2 = _GDIPlus_BitmapCrop($bmp2, 0, 0, 400, 400) _GDIPlus_ImageSaveToFile($bmp2, "nouveau.jpg") _GDIPlus_BitmapDispose($bmp) _GDIPlus_BitmapDispose($bmp2) _GDIPlus_Shutdown() Func _GDIPlus_BitmapCrop($bmp, $x,$y,$w, $h,$Quality =$InterpolationModeHighQualityBicubic) _GDIPlus_Startup() ; --- Local $hBmp = _WinApi_CreateBitmap ($x, $y, 1, 32) Local $bmp2 = _GDIPlus_BitmapCreateFromHBITMAP ($hBmp) Local $graphic = _GDIPlus_ImageGetGraphicsContext ($bmp2) _GDIPLUS_GraphicsSetInterpolationMode ($graphic, $Quality) _GDIPlus_GraphicsDrawImageRectRect ($graphic, $bmp, $x, $y, $w, $h, 0, 0, $w, $h) ; --- _GDIPlus_GraphicsDispose($graphic) _WinApi_DeleteObject($hBmp) ; --- _GDIPlus_Shutdown() ; --- Return $bmp2 EndFunc But if my solution works, that faster, I think. Can you test it using the latest stable version of autoit ? Thanks Ps: by the same way, can I open AlbumArt.jpg, and save it to file albumart.jpg Pss: can I do a GDI startup at the beginning of my program, then use multiple times this function to process multiple images and then at the end of the program, I close it. Or do I've to "startup" it and "close" it every time ? Edited January 15, 2012 by lesolutionneur
UEZ Posted January 15, 2012 Posted January 15, 2012 (edited) Of course it works for me. Best practise is to use _GDIPlus_Startup() at startup and before exiting _GDIPlus_Shutdown() otherwise you will slow down your script. You can overwrite the image of course and your version is better than the example from the french forum. Br, UEZ Edited January 15, 2012 by 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
lesolutionneur Posted January 15, 2012 Author Posted January 15, 2012 Ok thanks, but don't I have to remove these two lines ? $iImageWidth = _GDIPlus_ImageGetWidth($hImage) $iImageHeight = _GDIPlus_ImageGetHeight($hImage) 'cause if I give 0,0,400,400, 400 and 400 are overwrited by these two lines, aren't they ?
lesolutionneur Posted January 16, 2012 Author Posted January 16, 2012 Up I just need a small answer an the topic will be solved
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