-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgdiplusimage.go
280 lines (227 loc) · 7.48 KB
/
gdiplusimage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package gdiplus
import (
"unsafe"
. "github.com/tryor/winapi"
)
type IImage interface {
GetNativeImage() *GpImage
}
type Image struct {
GdiplusBase
nativeImage *GpImage
}
func NewImage(filename string, useEmbeddedColorManagement ...BOOL) (*Image, error) {
image := &Image{}
if len(useEmbeddedColorManagement) > 0 && useEmbeddedColorManagement[0] {
image.setStatus(GdipLoadImageFromFileICM(filename, &image.nativeImage))
} else {
image.setStatus(GdipLoadImageFromFile(filename, &image.nativeImage))
}
return image, image.LastError
}
func (this *Image) Release() {
if this.nativeImage != nil {
this.setStatus(GdipDisposeImage(this.nativeImage))
this.nativeImage = nil
}
}
func (this *Image) GetNativeImage() *GpImage {
return this.nativeImage
}
func (this *Image) Clone() *Image {
image := &Image{}
this.setStatus(GdipCloneImage(this.nativeImage, &image.nativeImage))
return image
}
func (this *Image) GetEncoderParameterListSize(clsidEncoder *CLSID) (size UINT) {
this.setStatus(GdipGetEncoderParameterListSize(this.nativeImage,
clsidEncoder,
&size))
return
}
func (this *Image) GetEncoderParameterList(
clsidEncoder *CLSID, size UINT) (buffer []EncoderParameters, status Status) {
buffer = make([]EncoderParameters, size)
status = this.setStatus(GdipGetEncoderParameterList(this.nativeImage,
clsidEncoder,
buffer))
return
}
func (this *Image) Save(
filename string,
clsidEncoder *CLSID,
encoderParams *EncoderParameters) Status {
return this.setStatus(GdipSaveImageToFile(this.nativeImage,
filename,
clsidEncoder,
encoderParams))
}
func (this *Image) SaveAdd(encoderParams *EncoderParameters) Status {
return this.setStatus(GdipSaveAdd(this.nativeImage, encoderParams))
}
func (this *Image) SaveAdd2(newImage IImage, encoderParams *EncoderParameters) Status {
if newImage == nil {
return this.setStatus(InvalidParameter, nil)
}
return this.setStatus(GdipSaveAddImage(this.nativeImage,
newImage.GetNativeImage(), encoderParams))
}
func (this *Image) GetType() ImageType {
var typ ImageType = ImageTypeUnknown
this.setStatus(GdipGetImageType(this.nativeImage, &typ))
return typ
}
func (this *Image) GetPhysicalDimension() (size *SizeF, status Status) {
size = &SizeF{}
status = this.setStatus(GdipGetImageDimension(this.nativeImage,
&size.Width, &size.Height))
return
}
func (this *Image) GetBounds() (srcRect *RectF, srcUnit Unit, status Status) {
srcRect = &RectF{}
status = this.setStatus(GdipGetImageBounds(this.nativeImage, srcRect, &srcUnit))
return
}
func (this *Image) GetWidth() (width UINT) {
this.setStatus(GdipGetImageWidth(this.nativeImage, &width))
return
}
func (this *Image) GetHeight() (height UINT) {
this.setStatus(GdipGetImageHeight(this.nativeImage, &height))
return
}
func (this *Image) GetHorizontalResolution() (resolution REAL) {
this.setStatus(GdipGetImageHorizontalResolution(this.nativeImage, &resolution))
return
}
func (this *Image) GetVerticalResolution() (resolution REAL) {
this.setStatus(GdipGetImageVerticalResolution(this.nativeImage, &resolution))
return
}
func (this *Image) GetFlags() (flags UINT) {
this.setStatus(GdipGetImageFlags(this.nativeImage, &flags))
return
}
func (this *Image) GetRawFormat() (format GUID, status Status) {
status = this.setStatus(GdipGetImageRawFormat(this.nativeImage, &format))
return
}
func (this *Image) GetPixelFormat() (format PixelFormat) {
this.setStatus(GdipGetImagePixelFormat(this.nativeImage, &format))
return
}
func (this *Image) GetPaletteSize() (size INT) {
this.setStatus(GdipGetImagePaletteSize(this.nativeImage, &size))
return
}
func (this *Image) GetPalette(size INT) (palette *ColorPalette, status Status) {
palette_ := make([]byte, size)
palette = (*ColorPalette)(unsafe.Pointer(&palette_[0]))
status = this.setStatus(GdipGetImagePalette(this.nativeImage, palette, size))
return
}
func (this *Image) SetPalette(palette *ColorPalette) Status {
return this.setStatus(GdipSetImagePalette(this.nativeImage, palette))
}
func (this *Image) GetThumbnailImage(thumbWidth UINT, thumbHeight UINT,
callback GetThumbnailImageAbort, callbackData DATA_PTR) *Image {
newImage := &Image{}
this.setStatus(GdipGetImageThumbnail(this.nativeImage,
thumbWidth, thumbHeight,
&newImage.nativeImage,
callback, callbackData))
return newImage
}
func (this *Image) GetFrameDimensionsCount() (count UINT) {
this.setStatus(GdipImageGetFrameDimensionsCount(this.nativeImage,
&count))
return
}
func (this *Image) GetFrameDimensionsList(count UINT) (dimensionIDs []GUID, status Status) {
dimensionIDs = make([]GUID, count)
status = this.setStatus(GdipImageGetFrameDimensionsList(this.nativeImage,
dimensionIDs))
return
}
func (this *Image) GetFrameCount(dimensionID *GUID) (count UINT) {
this.setStatus(GdipImageGetFrameCount(this.nativeImage,
dimensionID, &count))
return
}
func (this *Image) SelectActiveFrame(
dimensionID *GUID, frameIndex UINT) Status {
return this.setStatus(GdipImageSelectActiveFrame(this.nativeImage,
dimensionID, frameIndex))
}
func (this *Image) RotateFlip(rotateFlipType RotateFlipType) Status {
return this.setStatus(GdipImageRotateFlip(this.nativeImage,
rotateFlipType))
}
func (this *Image) GetPropertyCount() (numProperty UINT) {
this.setStatus(GdipGetPropertyCount(this.nativeImage,
&numProperty))
return
}
func (this *Image) GetPropertyIdList(numOfProperty UINT) (list []PROPID, status Status) {
list = make([]PROPID, numOfProperty)
status = this.setStatus(GdipGetPropertyIdList(this.nativeImage, list))
return
}
func (this *Image) GetPropertyItemSize(
propId PROPID) (size UINT) {
this.setStatus(GdipGetPropertyItemSize(this.nativeImage,
propId, &size))
return
}
func (this *Image) GetPropertyItem(propId PROPID,
propSize UINT) (buffer *PropertyItem, status Status) {
if propSize == 0 {
status = this.setStatus(InvalidParameter, nil)
return
}
buffer_ := make([]byte, propSize)
buffer = (*PropertyItem)(unsafe.Pointer(&buffer_[0]))
status = this.setStatus(GdipGetPropertyItem(this.nativeImage,
propId, propSize, buffer))
return
}
func (this *Image) GetPropertySize() (totalBufferSize, numProperties UINT, status Status) {
status = this.setStatus(GdipGetPropertySize(this.nativeImage,
&totalBufferSize,
&numProperties))
return
}
func (this *Image) GetAllPropertyItems(
totalBufferSize, numProperties UINT) (allItems []PropertyItem, status Status) {
allItems_ := make([]byte, totalBufferSize)
allItemsPtr := (*PropertyItem)(unsafe.Pointer(&allItems_[0]))
status = this.setStatus(GdipGetAllPropertyItems(this.nativeImage,
totalBufferSize,
numProperties,
allItemsPtr))
if status == Ok {
allItems = make([]PropertyItem, numProperties)
for j := UINT(0); j < numProperties; j++ {
item := (*PropertyItem)(unsafe.Pointer(uintptr(unsafe.Pointer(allItemsPtr)) + uintptr(PropertyItem_SIZE*j)))
allItems[j] = *item
}
}
return
}
func (this *Image) RemovePropertyItem(propId PROPID) Status {
return this.setStatus(GdipRemovePropertyItem(this.nativeImage, propId))
}
func (this *Image) SetPropertyItem(item *PropertyItem) Status {
return this.setStatus(GdipSetPropertyItem(this.nativeImage, item))
}
//#if (GDIPVER >= 0x0110)
func (this *Image) FindFirstItem(item *ImageItemData) Status {
return this.setStatus(GdipFindFirstImageItem(this.nativeImage, item))
}
func (this *Image) FindNextItem(item *ImageItemData) Status {
return this.setStatus(GdipFindNextImageItem(this.nativeImage, item))
}
func (this *Image) GetItemData(item *ImageItemData) Status {
return this.setStatus(GdipGetImageItemData(this.nativeImage, item))
}
//#endif //(GDIPVER >= 0x0110)