Sign in to follow this  
Followers 0
markyrocks

issue with $GDIP_PXF16GRAYSCALE in gdiplus.au3 functions...

4 posts in this topic

#1 ·  Posted (edited)

ok so i've tried using this constant in a couple of different ways to try to do the same thing...I basically trying to take a screenshot and convert it to grayscale....

simple right? well for whatever reason is beyond me it just doesn't work. for every scenario i've tried that involves a $iFormat it if use the constant $GDIP_PXF16GRAYSCALE it just doesnt work. the script just ignores that line no errors or nothing but nothing comes out the other end either. I've checked the gdiplusconstants.au3.... its in there and i have all the necessary includes in my script. the functions i've tried work as far as i can tell except for the last one i tried idk what happened there but if i remove the constant $GDIP_PXF16GRAYSCALE from the function even replace it with a different $iFormat it seems to work fine.

anyways im on a win 8.1 64bit machine. I've only tested on running the script in x86 mode. idk i came here as a last resort. Idk if its some kinda bug or what the deal is. Please forgive the jumble of code.... have been messing with it for about 5 hours now....O main reason i came here is to see if some body could possibly test this on their machine?

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <Color.au3>
 #include <Array.au3>
#include "GDIPlusConstants.au3"

_GDIPlus_Startup()
$width=@DesktopWidth
$height=0    
$bottom=@DesktopHeight 
$screen=_ScreenCapture_Capture("",0,$height,$width,$bottom,False)
$bmp=_GDIPlus_BitmapCreateFromHBITMAP($screen)
 _WinAPI_DeleteObject($screen)

;$tPalette = _GDIPlus_PaletteInitialize(16,$GDIP_PaletteTypeFixedBW, "", False, $bmp)


;_GDIPlus_BitmapConvertFormat($bmp,$GDIP_PXF16GRAYSCALE,$GDIP_DitherTypeSolid,$GDIP_PaletteTypeFixedBW,$tPalette,0)
;$bmp= _GDIPlus_BitmapCloneArea($hbmp,0,0,50,50,$GDIP_PXF16RGB555) ;new,0x00101004

$hbmp=_GDIPlus_BitmapCloneArea($bmp,0,0,50,50,$GDIP_PXF16GRAYSCALE )
_GDIPlus_ImageSaveToFile($hbmp,@ScriptDir & "\grayscale.bmp")


;_GDIPlus_BitmapDispose($Rbmp)       
_GDIPlus_BitmapDispose($hbmp)
_GDIPlus_BitmapDispose($bmp)
_GDIPlus_Shutdown()

Edit also I'm using latest version of autoit

Edited by markyrocks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This may help:

#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>

GrayScale_Capture(@DesktopWidth, @DesktopHeight)

Func GrayScale_Capture($iWidth, $iHeight)
    Local $hIA, $tColorMatrix, $hHBmp, $hBitmap

    _GDIPlus_Startup() ;start GDI +

    $hIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object

    $tColorMatrix = _GDIPlus_ColorMatrixCreateGrayScale() ;create the grayscale color matrix

    _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $tColorMatrix) ;adjust the image color to grayscale

    $hHBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iHeight) ;create a GDI bitmap by capturing an area on desktop
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap

    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore

    _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $hIA) ;draw the bitmap while applying the color adjustment

    _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\grayscale.bmp")

    ;cleanup GDI+ resources
    _GDIPlus_ImageAttributesDispose($hIA)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example
Edited by mpower

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thank you for the example. I was kinda heading down that path at the end of my struggles. I just didn't have much left to give. I'll check it out here in a min.

!!DUDE your amazing you probably saved me at least 4 or 5 hours of messing around tyvm.

but wait a second if i was able to get other $iFormats to work is there a issue with the one i mentioned above or is it an issue with the way i was using it?

Edited by markyrocks

Share this post


Link to post
Share on other sites

Thank you for the example. I was kinda heading down that path at the end of my struggles. I just didn't have much left to give. I'll check it out here in a min.

!!DUDE your amazing you probably saved me at least 4 or 5 hours of messing around tyvm.

but wait a second if i was able to get other $iFormats to work is there a issue with the one i mentioned above or is it an issue with the way i was using it?

 

No worries, glad to help! :)

GDI+ is a bit of mystery to me. I try to avoid it where possible as it's somewhat complex (for me anyway). I would let someone who is proficient in GDI+ comment, but I suspect it was the way it was used in your script that wasn't quite right.

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