Sign in to follow this  
Followers 0
danielkza

Multidimensional arrays in DllStruct

6 posts in this topic

Is it possible to have multidimensional arrays in DLL Structs? The struct declaration is this:

typedef struct {
    REAL m[5][5];
} ColorMatrix;

It's from GDI+,and all GDI+functions treat reals as ints,but none of them has arrays like this one,and DllStructSetData only accepts one index.

Does anybody know how can i do it?

Share this post


Link to post
Share on other sites



Since there's no solution available,does anybody know an efficient way to set an GDI Image's tranparency,or even how to make a slideshow that does not lag with huge pictures(like 1600x1200)?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Have you tried

$tArray5x5 = DllStructCreate("align 4;int[5];int[5];int[5];int[5];int[5]")
;
$el_0_4 = DllStructGetData($tArray5x5, 1, 5)
$el_1_2 = DllStructGetData($tArray5x5, 2, 3)
;etc.
Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Have you tried

$tArray5x5 = DllStructCreate("align 4;int[5];int[5];int[5];int[5];int[5]")
;
$el_0_4 = DllStructGetData($tArray5x5, 1, 5)
$el_1_2 = DllStructGetData($tArray5x5, 2, 3)
;etc.
I Tried but no luck,i modified GraphicsDrawImageRectRect to accept the ImageAttribute,but nothing changes.

Definition of GDI's GdipSetImageAttributesColorMatrix:

GpStatus WINGDIPAPI GdipSetImageAttributesColorMatrix(GpImageAttributes *imageattr, ColorAdjustType type, BOOL enableFlag, GDIPCONST ColorMatrix* colorMatrix, GDIPCONST ColorMatrix* grayMatrix, ColorMatrixFlags flags)

My Code:

#include <GDIPlus2.au3>;modified
#include <GUIConstants.au3>

Global Const $tagGDIPCOLORMATRIX = "align 4;int[5];int[5];int[5];int[5];int[5]"

Global Const $ColorMatrixFlagsDefault = 0
Global Const $ColorMatrixFlagsSkipGrays = 1
Global Const $ColorMatrixFlagsAltGray = 2

Global Const $ColorAdjustTypeDefault = 0
Global Const $ColorAdjustTypeBitmap = 1
Global Const $ColorAdjustTypeBrush = 2
Global Const $ColorAdjustTypePen = 3
Global Const $ColorAdjustTypeText = 4
Global Const $ColorAdjustTypeCount = 5
Global Const $ColorAdjustTypeAny = 6

$GUI = GuiCreate("",400,400)
GuiSetState()
_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile(FileOpenDialog("","","JPG FIles(*.jpg)"))
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
$hImageAttr = _GDIPlus_ImageAttributeCreate()
Local $aColorMatrix[5][5] = [[1.0,0.1,0.0,1.0,0.0], _
                        [0.0,1.0,0.0,0.0,0.1], _
                        [1.0,0.1,1.0,0.0,0.0], _                        
                        [1.0,0.0,0.0,0.1,0.1], _                        
                        [1.0,0.0,1.0,0.0,1.0]]                      
$Ret = _GDIPlus_ImageAttributeSetColorMatrix($hImageAttr,$ColorAdjustTypeDefault,$aColorMatrix,$aColorMatrix,False,$ColorMatrixFlagsDefault)
MsgBox(0,0,@error & @LF & $Ret)
$W = _GDIPlus_ImageGetWidth($hImage)
$H = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics,$hImage,0,0,$W,$H,0,0,400,400,2);,$hImageAttr)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_ImageAttributeDispose($hImageAttr)

Func _GDIPlus_ImageAttributeCreate()
    Local $aResult,$pResult
    
    $aResult = DllCall($ghGDIPDll,"int","GdipCreateImageAttributes","int*",0)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[1])
EndFunc

Func _GDIPlus_ImageAttributeDispose(Const $hImageAttr)
    Local $aResult
    
    $aResult = DllCall($ghGDIPDll,"int","GdipDisposeImageAttributes","hwnd",$hImageAttr)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[0] == 0)
EndFunc
    
Func _GDIPlus_ImageAttributeSetColorMatrix(Const $pImageAttr,Const $iType,Const ByRef $aMatrix,Const ByRef $aGrayMatrix,Const $iEnable,Const $iFlags)
    Local $aResult,$tMatrix
    
    If UBound($aMatrix,0) <> 2 OR UBound($aMatrix,1) <> 5 OR UBound($aMatrix,2) <> 5 Then
        Return SetError(1)
    EndIF
        
    If UBound($aGrayMatrix,0) <> 2 OR UBound($aGrayMatrix,1) <> 5 OR UBound($aGrayMatrix,2) <> 5 Then
        Return SetError(2)
    EndIF
    
    $tMatrix = DllStructCreate($tagGDIPCOLORMATRIX)
    For $i = 1 To 5
        For $j = 1 to 5
            DllStructSetData($tMatrix,$i,$aMatrix[$i-1][$j-1],$j)
        Next
    Next
    $tGrayMatrix = DllStructCreate($tagGDIPCOLORMATRIX)
    For $i = 1 To 5
        For $j = 1 to 5
            DllStructSetData($tGrayMatrix,$i,$aGrayMatrix[$i-1][$j-1],$j)
        Next
    Next
    $aResult = DllCall($ghGDIPDll, _
        "int","GdipSetImageAttributesColorMatrix", _
        "hwnd",$pImageAttr,"int",$iType,"int",$iEnable, _
        "ptr",DllStructGetPtr($tMatrix),"ptr",DllStructGetPtr($tGrayMatrix), _
        "int",$iFlags)
    
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc

What am i doing wrong?

Share this post


Link to post
Share on other sites

What am i doing wrong?

Well, for one, you have the DllStruct of integers, and try to fit into it float values from $aColorMatrix. So make up your mind which is it, floats or ints. If it is floats, then DllStruct should be made of "float" elements too.

"be smart, drink your wine"

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