1 | ' Classes/System/Drawing/Image.ab
|
---|
2 |
|
---|
3 | Namespace System
|
---|
4 | Namespace Drawing
|
---|
5 |
|
---|
6 | Class Image
|
---|
7 | Implements IDisposable, ICloneable
|
---|
8 | Public
|
---|
9 | Sub Image(native As *GpImage)
|
---|
10 | nativeImage = native
|
---|
11 | End Sub
|
---|
12 |
|
---|
13 | ' FromNativeImage推奨
|
---|
14 | Function NativeImage() As *GpImage
|
---|
15 | NativeImage = nativeImage
|
---|
16 | End Function
|
---|
17 |
|
---|
18 | Static Function FromFile(filename As String, useEmbeddedColorManagement = False As Boolean) As Image
|
---|
19 | FromFile = FromFile(ToWCStr(filename), useEmbeddedColorManagement)
|
---|
20 | End Function
|
---|
21 |
|
---|
22 | Static Function FromFile(filename As PCWSTR, useEmbeddedColorManagement = False As Boolean) As Image
|
---|
23 | Dim native As *GpImage
|
---|
24 | If useEmbeddedColorManagement Then
|
---|
25 | SetStatus(GdipLoadImageFromFileICM(filename, native))
|
---|
26 | Else
|
---|
27 | SetStatus(GdipLoadImageFromFile(filename, native))
|
---|
28 | End If
|
---|
29 | FromFile = FromNativeImage(native)
|
---|
30 | End Function
|
---|
31 |
|
---|
32 | ' Static Function FromComStream(stream As IStream, useEmbeddedColorManagement = False As Boolean) As Image
|
---|
33 | ' Dim native As *GpImage
|
---|
34 | ' If useEmbeddedColorManagement Then
|
---|
35 | ' SetStatus(GdipLoadImageFromStreamICM(stream, native))
|
---|
36 | ' Else
|
---|
37 | ' SetStatus(GdipLoadImageFromStream(stream, native))
|
---|
38 | ' End If
|
---|
39 | ' FromComStream = FromNativeImage(native)
|
---|
40 | ' End Function
|
---|
41 |
|
---|
42 | ' Static Function FromABStream(stream As IO.Stream, useEmbeddedColorManagement = False As Boolean) As Image
|
---|
43 | ' Dim comStream = ComStreamFromABStream(stream)
|
---|
44 | ' Try
|
---|
45 | ' FromABStream = New FromComStream(comStream)
|
---|
46 | ' Finally
|
---|
47 | ' comStream.Release()
|
---|
48 | ' End Try
|
---|
49 | ' End Function
|
---|
50 |
|
---|
51 | Static Function FromNativeImage(native As *GpImage) As Image
|
---|
52 | Dim imageType = ImageTypeUnknown As ImageType
|
---|
53 | SetStatus(GdipGetImageType(nativeImage, imageType))
|
---|
54 | Select Case imageType
|
---|
55 | Case ImageTypeBitmap
|
---|
56 | FromNativeImage = New Bitmap(native)
|
---|
57 | ' Case ImageTypeMetafile
|
---|
58 | ' FromNativeImage = New Metafile(native)
|
---|
59 | Case Else
|
---|
60 | FromNativeImage = New Image(native)
|
---|
61 | End Select
|
---|
62 | End Function
|
---|
63 |
|
---|
64 | Sub Dispose()
|
---|
65 | If nativeImage <> 0 Then
|
---|
66 | GdipDisposeImage(nativeImage)
|
---|
67 | End If
|
---|
68 | nativeImage = 0
|
---|
69 | End Sub
|
---|
70 |
|
---|
71 | Sub ~Image()
|
---|
72 | Dispose()
|
---|
73 | End Sub
|
---|
74 |
|
---|
75 | Function Clone() As Image
|
---|
76 | Dim cloned As *GpImage
|
---|
77 | SetStatus(GdipCloneImage(nativeImage, cloned))
|
---|
78 | Clone = FromNativeImage(cloned)
|
---|
79 | End Function
|
---|
80 |
|
---|
81 | Sub Save(filename As String, format As Imaging.ImageFormat)
|
---|
82 | SaveImpl(ToWCStr(filename), format.Guid)
|
---|
83 | End Sub
|
---|
84 |
|
---|
85 | Sub Save(filename As PCWSTR, format As Imaging.ImageFormat)
|
---|
86 | SaveImpl(filename, format.Guid)
|
---|
87 | End Sub
|
---|
88 | /*
|
---|
89 | Sub Save(stream As IStream, format As Imaging.ImageFormat)
|
---|
90 | SaveImpl(stream, format.Guid)
|
---|
91 | End Sub
|
---|
92 |
|
---|
93 | Sub Save(stream As IO.Stream, format As Imaging.ImageFormat)
|
---|
94 | SaveImpl(stream, format.Guid)
|
---|
95 | End Sub
|
---|
96 | */
|
---|
97 | Sub Save(filename As String, encoder As Imaging.ImageCodecInfo, encoderParams As Imaging.EncoderParameters)
|
---|
98 | SaveImpl(ToWCStr(filename), encoder.Clsid, ToNativeEncoderParameters(encoderParams))
|
---|
99 | End Sub
|
---|
100 |
|
---|
101 | Sub Save(filename As PCWSTR, encoder As Imaging.ImageCodecInfo, encoderParams As Imaging.EncoderParameters)
|
---|
102 | SaveImpl(filename, encoder.Clsid, ToNativeEncoderParameters(encoderParams))
|
---|
103 | End Sub
|
---|
104 | /*
|
---|
105 | Sub Save(stream As IO.Stream, encoder As Imaging.ImageCodecInfo, encoderParams As Imaging.EncoderParameters)
|
---|
106 | SaveImpl(stream, encoder.Clsid, ToNativeEncoderParameters(encoderParams))
|
---|
107 | End Sub
|
---|
108 |
|
---|
109 | Sub Save(stream As IStream, encoder As Imaging.ImageCodecInfo, encoderParams As Imaging.EncoderParameters)
|
---|
110 | SaveImpl(stream, encoder.Clsid, ToNativeEncoderParameters(encoderParams))
|
---|
111 | End Sub
|
---|
112 | */
|
---|
113 | Private
|
---|
114 | Static Function ToNativeEncoderParameters(encoderParams As Imaging.EncoderParameters) As *Gdiplus.EncoderParameters
|
---|
115 | If ActiveBasic.IsNothing(encoderParams) Then
|
---|
116 | ToNativeEncoderParameters = 0
|
---|
117 | Else
|
---|
118 | ToNativeEncoderParameters = encoderParams.Params
|
---|
119 | End If
|
---|
120 | End Function
|
---|
121 |
|
---|
122 | Sub SaveImpl(filename As PCWSTR, ByRef clsidEncoder As CLSID, encoderParams = 0 As *Gdiplus.EncoderParameters)
|
---|
123 | SetStatus(GdipSaveImageToFile(nativeImage, filename, clsidEncoder, encoderParams))
|
---|
124 | End Sub
|
---|
125 | /*
|
---|
126 | Sub SaveImpl(stream As IStream, ByRef clsidEncoder As CLSID, encoderParams = 0 As *Gdiplus.EncoderParameters)
|
---|
127 | SetStatus(GdipSaveImageToStream(stream, clsidEncoder, encoderParams)
|
---|
128 | End Sub
|
---|
129 | */
|
---|
130 | Public
|
---|
131 | Sub SaveAdd(encoderParams As Imaging.EncoderParameters)
|
---|
132 | SetStatus(GdipSaveAdd(nativeImage, ByVal ToNativeEncoderParameters(encoderParams)))
|
---|
133 | End Sub
|
---|
134 |
|
---|
135 | Sub SaveAdd(newImage As Image, encoderParams As Imaging.EncoderParameters)
|
---|
136 | If ActiveBasic.IsNothing(newImage) Then
|
---|
137 | Throw New ArgumentNullException("newImage")
|
---|
138 | End If
|
---|
139 | SetStatus(GdipSaveAddImage(nativeImage, newImage.NativeImage, ByVal ToNativeEncoderParameters(encoderParams)))
|
---|
140 | End Sub
|
---|
141 |
|
---|
142 | Function PhysicalDimension() As SizeF
|
---|
143 | With PhysicalDimension
|
---|
144 | SetStatus(GdipGetImageDimension(nativeImage, .Width, .Height))
|
---|
145 | End With
|
---|
146 | End Function
|
---|
147 | /*
|
---|
148 | Function GetBounds(pageUnit As GraphicsUnit) As RectangleF
|
---|
149 | SetStatus(GdipGetImageBounds(nativeImage, pageUnit, GetBounds))
|
---|
150 | End Function
|
---|
151 | */
|
---|
152 | Function Width() As DWord
|
---|
153 | SetStatus(GdipGetImageWidth(nativeImage, Width))
|
---|
154 | End Function
|
---|
155 |
|
---|
156 | Function Height() As DWord
|
---|
157 | SetStatus(GdipGetImageHeight(nativeImage, Height))
|
---|
158 | End Function
|
---|
159 |
|
---|
160 | Function Size() As Size
|
---|
161 | Size.Width = This.Width
|
---|
162 | Size.Height = This.Height
|
---|
163 | End Function
|
---|
164 |
|
---|
165 | Function HorizontalResolution() As Single
|
---|
166 | SetStatus(GdipGetImageHorizontalResolution(nativeImage, HorizontalResolution))
|
---|
167 | End Function
|
---|
168 |
|
---|
169 | Function VerticalResolution() As Single
|
---|
170 | SetStatus(GdipGetImageVerticalResolution(nativeImage, VerticalResolution))
|
---|
171 | End Function
|
---|
172 |
|
---|
173 | Function Flags() As DWord
|
---|
174 | SetStatus(GdipGetImageFlags(nativeImage, Height))
|
---|
175 | End Function
|
---|
176 | /*
|
---|
177 | Status GetRawFormat(OUT GUID *format);
|
---|
178 | */
|
---|
179 | ' Function PixelFormat() As Imaging.PixelFormat
|
---|
180 | ' SetStatus(GdipGetImagePixelFormat(nativeImage, PixelFormat))
|
---|
181 | ' End Function
|
---|
182 |
|
---|
183 | ' Palette - GetPaletteSize/GetPalette/SetPalette
|
---|
184 | /*
|
---|
185 | Image* GetThumbnailImage(IN UINT thumbWidth,
|
---|
186 | IN UINT thumbHeight,
|
---|
187 | IN GetThumbnailImageAbort callback = NULL,
|
---|
188 | IN VOID* callbackData = NULL);
|
---|
189 | */
|
---|
190 | ' FrameDimensionsList - GetFrameDimensionsCount/GetFrameDimensionsList
|
---|
191 | ' GetFrameCount
|
---|
192 | ' SelectActiveFrame
|
---|
193 |
|
---|
194 | Sub RotateFlip(rotateFlipType As RotateFlipType)
|
---|
195 | SetStatus(GdipImageRotateFlip(nativeImage, rotateFlipType))
|
---|
196 | End Sub
|
---|
197 |
|
---|
198 | ' PropertyIdList - GetPropertyCount/GetPropertyIdList
|
---|
199 | ' GetPropertyItem - GetPropertyItemSize/GetPropertyItem
|
---|
200 | ' PropertyItems - GetPropertySize/GetAllPropertyItems
|
---|
201 | ' RemovePropertyItem
|
---|
202 | ' SetPropertyItem
|
---|
203 | ' GetEncoderParameterList - GetEncoderParameterList/GetEncoderParameterListSize
|
---|
204 |
|
---|
205 | Private
|
---|
206 | nativeImage As *GpImage
|
---|
207 | End Class
|
---|
208 |
|
---|
209 | Namespace Imaging
|
---|
210 | Class ImageCodecInfo
|
---|
211 | Public
|
---|
212 | Sub ImageCodecInfo(ByRef nativeImageCodecInfo As Gdiplus.ImageCodecInfo)
|
---|
213 | ici = nativeImageCodecInfo
|
---|
214 | End Sub
|
---|
215 |
|
---|
216 | Function Clsid() As CLSID
|
---|
217 | Clsid = ici.FormatID
|
---|
218 | End Function
|
---|
219 |
|
---|
220 | Function FormatID() As GUID
|
---|
221 | FormatID = ici.FormatID
|
---|
222 | End Function
|
---|
223 |
|
---|
224 | Function CodecName() As String
|
---|
225 | CodecName = New String(ici.CodecName)
|
---|
226 | End Function
|
---|
227 |
|
---|
228 | Function DllName() As String
|
---|
229 | DllName = New String(ici.DllName)
|
---|
230 | End Function
|
---|
231 |
|
---|
232 | Function FormatDescription() As String
|
---|
233 | FormatDescription = New String(ici.FormatDescription)
|
---|
234 | End Function
|
---|
235 |
|
---|
236 | Function FilenameExtension() As String
|
---|
237 | FilenameExtension = New String(ici.FilenameExtension)
|
---|
238 | End Function
|
---|
239 |
|
---|
240 | ' Function Flags() As ImageCodecFlags
|
---|
241 | ' Flags = ici.Flags
|
---|
242 | ' End Function
|
---|
243 |
|
---|
244 | Function Version() As DWord
|
---|
245 | Version = ici.Version
|
---|
246 | End Function
|
---|
247 |
|
---|
248 | ' SignaturePatterns
|
---|
249 | ' SignatureMasks
|
---|
250 |
|
---|
251 | Static Function GetImageDecoders() As Collections.Generic.IEnumerable<ImageCodecInfo>
|
---|
252 | Dim num As DWord
|
---|
253 | Dim bufSize As DWord
|
---|
254 | SetStatus(GdipGetImageDecodersSize(num, bufSize))
|
---|
255 | Dim pici = GC_malloc_atomic(bufSize) As *Gdiplus.ImageCodecInfo
|
---|
256 | SetStatus(GdipGetImageDecoders(num, bufSize, pici))
|
---|
257 | GetImageDecoders = ImageCodecInfoPtrToEnumerable(pici, num)
|
---|
258 | End Function
|
---|
259 |
|
---|
260 | Static Function GetImageEncoders() As Collections.Generic.IEnumerable<ImageCodecInfo>
|
---|
261 | Dim num As DWord
|
---|
262 | Dim bufSize As DWord
|
---|
263 | SetStatus(GdipGetImageEncodersSize(num, bufSize))
|
---|
264 | Dim pici = GC_malloc_atomic(bufSize) As *Gdiplus.ImageCodecInfo
|
---|
265 | SetStatus(GdipGetImageEncoders(num, bufSize, pici))
|
---|
266 | GetImageEncoders = ImageCodecInfoPtrToEnumerable(pici, num)
|
---|
267 | End Function
|
---|
268 |
|
---|
269 | Private
|
---|
270 | Static Function ImageCodecInfoPtrToEnumerable(pici As *Gdiplus.ImageCodecInfo, n As DWord) As Collections.Generic.IEnumerable<ImageCodecInfo>
|
---|
271 | Dim l = New Collections.Generic.List<ImageCodecInfo>(n)
|
---|
272 | Dim i As DWord
|
---|
273 | For i = 0 To ELM(n)
|
---|
274 | l.Add(New ImageCodecInfo(pici[i]))
|
---|
275 | Next
|
---|
276 | Dim il = l As Collections.Generic.IList<ImageCodecInfo>
|
---|
277 | ImageCodecInfoPtrToEnumerable = il
|
---|
278 | End Function
|
---|
279 |
|
---|
280 | ici As Gdiplus.ImageCodecInfo
|
---|
281 | End Class
|
---|
282 |
|
---|
283 | Class ImageFormat
|
---|
284 | Public
|
---|
285 | Function Guid() As GUID
|
---|
286 | Guid = guid
|
---|
287 | End Function
|
---|
288 |
|
---|
289 | Override Function Equals(y As Object) As Boolean
|
---|
290 | If This.GetType().Equals(y.GetType()) Then
|
---|
291 | Dim yi = y As ImageFormat
|
---|
292 | Equals = IsEqualGUID(This.guid, yi.guid) As Boolean
|
---|
293 | Else
|
---|
294 | Equals = False
|
---|
295 | End If
|
---|
296 | End Function
|
---|
297 |
|
---|
298 | Override Function GetHashCode() As Long
|
---|
299 | GetHashCode = _System_HashFromGUID(guid)
|
---|
300 | End Function
|
---|
301 |
|
---|
302 | Static Function MemoryBmp() As ImageFormat
|
---|
303 | Return New ImageFormat(Gdiplus.ImageFormatMemoryBMP)
|
---|
304 | End Function
|
---|
305 |
|
---|
306 | Static Function Bmp() As ImageFormat
|
---|
307 | Return New ImageFormat(Gdiplus.ImageFormatBMP)
|
---|
308 | End Function
|
---|
309 |
|
---|
310 | Static Function Emf() As ImageFormat
|
---|
311 | Return New ImageFormat(Gdiplus.ImageFormatEMF)
|
---|
312 | End Function
|
---|
313 |
|
---|
314 | Static Function Wmf() As ImageFormat
|
---|
315 | Return New ImageFormat(Gdiplus.ImageFormatWMF)
|
---|
316 | End Function
|
---|
317 |
|
---|
318 | Static Function Jpeg() As ImageFormat
|
---|
319 | Return New ImageFormat(Gdiplus.ImageFormatJPEG)
|
---|
320 | End Function
|
---|
321 |
|
---|
322 | Static Function Png() As ImageFormat
|
---|
323 | Return New ImageFormat(Gdiplus.ImageFormatPNG)
|
---|
324 | End Function
|
---|
325 |
|
---|
326 | Static Function Gif() As ImageFormat
|
---|
327 | Return New ImageFormat(Gdiplus.ImageFormatGIF)
|
---|
328 | End Function
|
---|
329 |
|
---|
330 | Static Function Tiff() As ImageFormat
|
---|
331 | Return New ImageFormat(Gdiplus.ImageFormatTIFF)
|
---|
332 | End Function
|
---|
333 |
|
---|
334 | Static Function Exif() As ImageFormat
|
---|
335 | Return New ImageFormat(Gdiplus.ImageFormatEXIF)
|
---|
336 | End Function
|
---|
337 |
|
---|
338 | Static Function Icon() As ImageFormat
|
---|
339 | Return New ImageFormat(Gdiplus.ImageFormatIcon)
|
---|
340 | End Function
|
---|
341 |
|
---|
342 | Private
|
---|
343 | Sub ImageFormat(ByRef codecGuid As GUID)
|
---|
344 | guid = codecGuid
|
---|
345 | End Sub
|
---|
346 |
|
---|
347 | guid As GUID
|
---|
348 | End Class
|
---|
349 |
|
---|
350 | Class EncoderParameters
|
---|
351 | Public
|
---|
352 | Sub EncoderParameters()
|
---|
353 | init(1)
|
---|
354 | End Sub
|
---|
355 |
|
---|
356 | Sub EncoderParameters(n As Long)
|
---|
357 | init(n)
|
---|
358 | End Sub
|
---|
359 |
|
---|
360 | Function Params() As *EncoderParameter
|
---|
361 | Params = eps->Parameter
|
---|
362 | End Function
|
---|
363 | Private
|
---|
364 | Sub init(n As Long)
|
---|
365 | Dim size = SizeOf (Gdiplus.EncoderParameters) + SizeOf (EncoderParameter) * n
|
---|
366 | eps = GC_malloc(size)
|
---|
367 | ZeroMemory(eps, size)
|
---|
368 | eps->Count = n
|
---|
369 | End Sub
|
---|
370 |
|
---|
371 | eps As *Gdiplus.EncoderParameters
|
---|
372 | End Class
|
---|
373 | End Namespace
|
---|
374 |
|
---|
375 | End Namespace
|
---|
376 | End Namespace
|
---|
377 |
|
---|
378 | Namespace Gdiplus
|
---|
379 |
|
---|
380 | Type ImageCodecInfo
|
---|
381 | Clsid As CLSID
|
---|
382 | FormatID As GUID
|
---|
383 | CodecName As PCWSTR
|
---|
384 | DllName As PCWSTR
|
---|
385 | FormatDescription As PCWSTR
|
---|
386 | FilenameExtension As PCWSTR
|
---|
387 | MimeType As PCWSTR
|
---|
388 | Flags As DWord
|
---|
389 | Version As DWord
|
---|
390 | SigCount As DWord
|
---|
391 | SigSize As DWord
|
---|
392 | SigPattern As *Byte
|
---|
393 | SigMask As *Byte
|
---|
394 | End Type
|
---|
395 |
|
---|
396 | Type Align(8) EncoderParameters
|
---|
397 | Count As DWord
|
---|
398 | Parameter[0] As System.Drawing.Imaging.EncoderParameter
|
---|
399 | End Type
|
---|
400 |
|
---|
401 | End Namespace
|
---|