Ticket #489: Example_GDIPlus_ImageSaveAddImage_ImageSaveAdd.au3

File Example_GDIPlus_ImageSaveAddImage_ImageSaveAdd.au3, 5.0 KB (added by smashly, 16 years ago)

Example_GDIPlus_ImageSaveAddImage_ImageSaveAdd.au3

Line 
1#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
2#include <GDIPlus.au3>
3
4Opt('MustDeclareVars', 1)
5
6_MakeMyMultiPageTif(@MyDocumentsDir & "\GDIPlus_MultiPage.tif")
7
8Func _MakeMyMultiPageTif($sOutFile)
9    Local $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\Advanced\Images"
10    Local $sCLSID, $tData, $tParams, $hImage1, $hImage2, $hImage3   
11       
12        _GDIPlus_Startup()
13   
14        $sCLSID = _GDIPlus_EncodersGetCLSID ("TIF")
15
16    ; Create the Const Encoder Value Type struct
17        $tData = DllStructCreate("int Data")
18   
19        ; Put the Const Encoder Value Type into the struct
20        DllStructSetData($tData, "Data", $GDIP_EVTMULTIFRAME)
21       
22        ;Initiate the Encoder Parameters
23    $tParams = _GDIPlus_ParamInit (1)
24    _GDIPlus_ParamAdd ($tParams, $GDIP_EPGSAVEFLAG, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))
25
26    ; Load 3 images that will be put into the tif file, the images can be different formats and sizes.
27        $hImage1 = _GDIPlus_ImageLoadFromFile($sPath & "\Red.bmp")
28    $hImage2 = _GDIPlus_ImageLoadFromFile($sPath & "\Green.bmp")
29    $hImage3 = _GDIPlus_ImageLoadFromFile($sPath & "\Blue.bmp")
30
31    ; Save the first loaded image passing on the Encoder Parameters
32        _GDIPlus_ImageSaveToFileEx($hImage1, $sOutFile, $sCLSID, DllStructGetPtr($tParams))
33
34    ; Now we have saved the first image into the tif we can set the Encoder Value Type again to add the next frames
35        DllStructSetData($tData, "Data", $GDIP_EVTFRAMEDIMENSIONPAGE)
36    $tParams = _GDIPlus_ParamInit (1)
37    _GDIPlus_ParamAdd ($tParams, $GDIP_EPGSAVEFLAG, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))
38
39    ; Now we add the 2nd frame
40    _GDIPlus_ImageSaveAddImage($hImage1, $hImage2, DllStructGetPtr($tParams))
41       
42        ; Now we add the 3rd frame
43    _GDIPlus_ImageSaveAddImage($hImage1, $hImage3, DllStructGetPtr($tParams))
44
45    ; My images are now added to the tif file I want to set the Encoder Value Type again to flush and finalise
46    DllStructSetData($tData, "Data", $GDIP_EVTFLUSH)
47    $tParams = _GDIPlus_ParamInit (1)
48    _GDIPlus_ParamAdd ($tParams, $GDIP_EPGSAVEFLAG, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))
49   
50        ; Now the final step to flush the encoder and finalize the image
51        _GDIPlus_ImageSaveAdd($hImage1, DllStructGetPtr($tParams))
52
53        ; Tidy up the 3 images we loaded and shutdown.
54        _GDIPlus_ImageDispose($hImage1)
55    _GDIPlus_ImageDispose($hImage2)
56        _GDIPlus_ImageDispose($hImage3)
57    _GDIPlus_Shutdown()
58EndFunc
59
60; #FUNCTION# ====================================================================================================================
61; Name...........: _GDIPlus_ImageSaveAddImage
62; Description ...: Adds a frame to a file or stream specified in a previous call to the _GDIPlus_ImageSaveToFileEx.
63; Syntax.........: _GDIPlus_ImageSaveAddImage($hImage, $hImageNew, $pParams)
64; Parameters ....: $hImage      - Handle to an image object
65;                  $hImageNew   - Handle to the new image object to add
66;                  $pParams     - Pointer to a $tagGDIPPENCODERPARAMS structure
67; Return values .: Success      - True
68;                  Failure      - False
69; Author ........: Smashly
70; Modified.......:
71; Remarks .......:
72; Related .......: _GDIPlus_ImageLoadFromFile, _GDIPlus_ImageSaveToFileEx, _GDIPlus_ImageSaveAdd, $tagGDIPPENCODERPARAMS
73; Link ..........; @@MsdnLink@@ GdipSaveAddImage
74; Example .......; Yes
75; ===============================================================================================================================
76Func _GDIPlus_ImageSaveAddImage($hImage, $hImageNew, $pParams)
77        Local $aResult
78       
79        $aResult = DllCall($ghGDIPDll, "int", "GdipSaveAddImage", "hwnd", $hImage, "hwnd", $hImageNew, "ptr", $pParams)
80        If @error Then Return SetError(@error, @extended, False)
81        Return SetError($aResult[0], 0, $aResult[0] = 0)
82EndFunc
83
84; #FUNCTION# ====================================================================================================================
85; Name...........: _GDIPlus_ImageSaveAdd
86; Description ...: Save selected frames from a multiple-frame image to another multiple-frame image.
87; Syntax.........: _GDIPlus_ImageSaveAdd($hImage, $pParams)
88; Parameters ....: $hImage      - Handle to an image object
89;                  $pParams     - Pointer to a $tagGDIPPENCODERPARAMS structure
90; Return values .: Success      - True
91;                  Failure      - False
92; Author ........: Smashly
93; Modified.......:
94; Remarks .......:
95; Related .......: _GDIPlus_ImageLoadFromFile, _GDIPlus_ImageSaveToFileEx, _GDIPlus_ImageSaveAddImage, $tagGDIPPENCODERPARAMS
96; Link ..........; @@MsdnLink@@ GdipSaveAdd
97; Example .......; Yes
98; ===============================================================================================================================
99Func _GDIPlus_ImageSaveAdd($hImage, $pParams)
100        Local $aResult
101       
102        $aResult = DllCall($ghGDIPDll, "int", "GdipSaveAdd", "hwnd", $hImage, "ptr", $pParams)
103        If @error Then Return SetError(@error, @extended, False)
104        Return SetError($aResult[0], 0, $aResult[0] = 0)
105EndFunc