1 | #include <GDIPlus.au3> |
---|
2 | |
---|
3 | _GDIPlus_Startup() |
---|
4 | |
---|
5 | Local $sSourceImageFileName = @ScriptDir & "\TestImage.png" |
---|
6 | Local $sTestOldScaleFileName = @ScriptDir & "\TestOldScale.png" |
---|
7 | Local $sTestNewScaleFileName = @ScriptDir & "\TestNewScale.png" |
---|
8 | Local $sTestOldResizeFileName = @ScriptDir & "\TestOldResize.png" |
---|
9 | Local $sTestNewResizeFileName = @ScriptDir & "\TestNewResize.png" |
---|
10 | |
---|
11 | Local $hImage = _GDIPlus_ImageLoadFromFile($sSourceImageFileName) |
---|
12 | Local $iSourceWidth = _GDIPlus_ImageGetWidth($hImage) |
---|
13 | Local $iSourceHeight = _GDIPlus_ImageGetHeight($hImage) |
---|
14 | |
---|
15 | Local $hBitmapOldScale = _GDIPlus_ImageScale($hImage, 4, 4, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC) |
---|
16 | _GDIPlus_ImageSaveToFile($hBitmapOldScale, $sTestOldScaleFileName) ; also frees bitmap by default |
---|
17 | |
---|
18 | Local $hBitmapNewScale = My_GDIPlus_ImageScale($hImage, 4, 4, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC) |
---|
19 | _GDIPlus_ImageSaveToFile($hBitmapNewScale, $sTestNewScaleFileName) ; also frees bitmap by default |
---|
20 | |
---|
21 | Local $hBitmapOldResize = _GDIPlus_ImageResize($hImage, $iSourceWidth * 4, $iSourceHeight * 4, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC) |
---|
22 | _GDIPlus_ImageSaveToFile($hBitmapOldResize, $sTestOldResizeFileName) ; also frees bitmap by default |
---|
23 | |
---|
24 | Local $hBitmapNewResize = My_GDIPlus_ImageResize($hImage, $iSourceWidth * 4, $iSourceHeight * 4, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC) |
---|
25 | _GDIPlus_ImageSaveToFile($hBitmapNewResize, $sTestNewResizeFileName) ; also frees bitmap by default |
---|
26 | |
---|
27 | _GDIPlus_ImageDispose($hImage) |
---|
28 | _GDIPlus_Shutdown() |
---|
29 | |
---|
30 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
---|
31 | ; Test these functions as potential replacements for those GDIPlus.au3 |
---|
32 | |
---|
33 | Func My_GDIPlus_ImageResize($hImage, $iNewWidth, $iNewHeight, $iInterpolationMode = $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC) |
---|
34 | Local $iOldWidth = _GDIPlus_ImageGetWidth($hImage) |
---|
35 | If @error Then Return SetError(1, 0, 0) |
---|
36 | Local $iOldHeight = _GDIPlus_ImageGetHeight($hImage) |
---|
37 | If @error Then Return SetError(2, 0, 0) |
---|
38 | Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iNewWidth, $iNewHeight) |
---|
39 | If @error Then Return SetError(3, 0, 0) |
---|
40 | Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) |
---|
41 | If @error Then |
---|
42 | _GDIPlus_BitmapDispose($hBitmap) |
---|
43 | Return SetError(4, 0, 0) |
---|
44 | EndIf |
---|
45 | Local $hAttributes = _GDIPlus_ImageAttributesCreate() |
---|
46 | If @error Then |
---|
47 | _GDIPlus_BitmapDispose($hBitmap) |
---|
48 | Return SetError(5, 0, 0) |
---|
49 | EndIf |
---|
50 | My_GDIPlus_ImageAttributesSetWrapMode($hAttributes, 3) |
---|
51 | If @error Then |
---|
52 | _GDIPlus_ImageAttributesDispose($hAttributes) |
---|
53 | _GDIPlus_GraphicsDispose($hGraphics) |
---|
54 | _GDIPlus_BitmapDispose($hBitmap) |
---|
55 | Return SetError(6, 0, 0) |
---|
56 | EndIf |
---|
57 | _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode) |
---|
58 | If @error Then |
---|
59 | _GDIPlus_ImageAttributesDispose($hAttributes) |
---|
60 | _GDIPlus_GraphicsDispose($hGraphics) |
---|
61 | _GDIPlus_BitmapDispose($hBitmap) |
---|
62 | Return SetError(7, 0, 0) |
---|
63 | EndIf |
---|
64 | _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, 0, 0, $iOldWidth, $iOldHeight, 0, 0, $iNewWidth, $iNewHeight, $hAttributes) |
---|
65 | If @error Then |
---|
66 | _GDIPlus_ImageAttributesDispose($hAttributes) |
---|
67 | _GDIPlus_GraphicsDispose($hGraphics) |
---|
68 | _GDIPlus_BitmapDispose($hBitmap) |
---|
69 | Return SetError(8, 0, 0) |
---|
70 | EndIf |
---|
71 | _GDIPlus_ImageAttributesDispose($hAttributes) |
---|
72 | _GDIPlus_GraphicsDispose($hGraphics) |
---|
73 | Return $hBitmap |
---|
74 | EndFunc ;==>My_GDIPlus_ImageResize |
---|
75 | |
---|
76 | Func My_GDIPlus_ImageScale($hImage, $iScaleW, $iScaleH, $iInterpolationMode = $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC) |
---|
77 | Local $iOldWidth = _GDIPlus_ImageGetWidth($hImage) |
---|
78 | Local $iNewWidth = $iOldWidth * $iScaleW |
---|
79 | If @error Then Return SetError(1, 0, 0) |
---|
80 | Local $iOldHeight = _GDIPlus_ImageGetHeight($hImage) |
---|
81 | Local $iNewHeight = $iOldHeight * $iScaleH |
---|
82 | If @error Then Return SetError(2, 0, 0) |
---|
83 | Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iNewWidth, $iNewHeight) |
---|
84 | If @error Then Return SetError(3, 0, 0) |
---|
85 | Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) |
---|
86 | If @error Then |
---|
87 | _GDIPlus_BitmapDispose($hBitmap) |
---|
88 | Return SetError(4, 0, 0) |
---|
89 | EndIf |
---|
90 | Local $hAttributes = _GDIPlus_ImageAttributesCreate() |
---|
91 | If @error Then |
---|
92 | _GDIPlus_BitmapDispose($hBitmap) |
---|
93 | Return SetError(5, 0, 0) |
---|
94 | EndIf |
---|
95 | My_GDIPlus_ImageAttributesSetWrapMode($hAttributes, 3) |
---|
96 | If @error Then |
---|
97 | _GDIPlus_ImageAttributesDispose($hAttributes) |
---|
98 | _GDIPlus_GraphicsDispose($hGraphics) |
---|
99 | _GDIPlus_BitmapDispose($hBitmap) |
---|
100 | Return SetError(6, 0, 0) |
---|
101 | EndIf |
---|
102 | _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode) |
---|
103 | If @error Then |
---|
104 | _GDIPlus_ImageAttributesDispose($hAttributes) |
---|
105 | _GDIPlus_GraphicsDispose($hGraphics) |
---|
106 | _GDIPlus_BitmapDispose($hBitmap) |
---|
107 | Return SetError(7, 0, 0) |
---|
108 | EndIf |
---|
109 | _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, 0, 0, $iOldWidth, $iOldHeight, 0, 0, $iNewWidth, $iNewHeight, $hAttributes) |
---|
110 | If @error Then |
---|
111 | _GDIPlus_ImageAttributesDispose($hAttributes) |
---|
112 | _GDIPlus_GraphicsDispose($hGraphics) |
---|
113 | _GDIPlus_BitmapDispose($hBitmap) |
---|
114 | Return SetError(8, 0, 0) |
---|
115 | EndIf |
---|
116 | _GDIPlus_ImageAttributesDispose($hAttributes) |
---|
117 | _GDIPlus_GraphicsDispose($hGraphics) |
---|
118 | Return $hBitmap |
---|
119 | EndFunc ;==>My_GDIPlus_ImageScale |
---|
120 | |
---|
121 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
---|
122 | ; New function for DLL call to SetWrapMode on an ImageAttribute |
---|
123 | |
---|
124 | Func My_GDIPlus_ImageAttributesSetWrapMode($hImageAttributes, $iWrapModeType = 0, $iArgb = 0, $bClamp = 0) |
---|
125 | Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipSetImageAttributesWrapMode", "handle", $hImageAttributes, "int", $iWrapModeType, "uint", $iArgb, "bool", $bClamp) |
---|
126 | If @error Then Return SetError(@error, @extended, False) |
---|
127 | If $aResult[0] Then Return SetError(10, $aResult[0], False) |
---|
128 | |
---|
129 | Return True |
---|
130 | EndFunc ;==>My_GDIPlus_ImageAttributesSetWrapMode |
---|
131 | |
---|