' Classes/System/Drawing/Image.ab Namespace System Namespace Drawing Class Image Implements IDisposable, ICloneable Public Sub Image(native As *GpImage) nativeImage = native End Sub ' FromNativeImage„§ Function NativeImage() As *GpImage NativeImage = nativeImage End Function Static Function FromFile(filename As PCWSTR, useEmbeddedColorManagement = False As Boolean) As Image Dim native As *GpImage If useEmbeddedColorManagement Then SetStatus(GdipLoadImageFromFileICM(filename, native)) Else SetStatus(GdipLoadImageFromFile(filename, native)) End If FromFile = FromNativeImage(native) End Function ' Static Function FromComStream(stream As IStream, useEmbeddedColorManagement = False As Boolean) As Image ' Dim native As *GpImage ' If useEmbeddedColorManagement Then ' SetStatus(GdipLoadImageFromStreamICM(stream, native)) ' Else ' SetStatus(GdipLoadImageFromStream(stream, native)) ' End If ' FromComStream = FromNativeImage(native) ' End Function ' Static Function FromABStream(stream As IO.Stream, useEmbeddedColorManagement = False As Boolean) As Image ' Dim comStream = ComStreamFromABStream(stream) ' Try ' FromABStream = New FromComStream(comStream) ' Finally ' comStream.Release() ' End Try ' End Function Static Function FromNativeImage(native As *GpImage) As Image Dim imageType = ImageTypeUnknown As ImageType SetStatus(GdipGetImageType(nativeImage, imageType)) Select Case imageType ' Case ImageTypeBitmap ' FromNativeImage = New Bitmap(native) ' Case ImageTypeMetafile ' FromNativeImage = New Metafile(native) Case Else FromNativeImage = New Image(native) End Select End Function Sub Dispose() If nativeImage <> 0 Then GdipDisposeImage(nativeImage) End If nativeImage = 0 End Sub Sub ~Image() Dispose() End Sub Function Clone() As Image Dim cloned As *GpImage SetStatus(GdipCloneImage(nativeImage, cloned)) Clone = FromNativeImage(cloned) End Function Sub Save(filename As PCWSTR, format As Imaging.ImageFormat) SaveImpl(filename, format.Guid) End Sub /* Sub Save(stream As IStream, format As Imaging.ImageFormat) SaveImpl(stream, format.Guid) End Sub Sub Save(stream As IO.Stream, format As Imaging.ImageFormat) SaveImpl(stream, format.Guid) End Sub */ Sub Save(filename As PCWSTR, encoder As Imaging.ImageCodecInfo, encoderParams As Imaging.EncoderParameters) SaveImpl(filename, encoder.Clsid, ToNativeEncoderParameters(encoderParams)) End Sub /* Sub Save(stream As IO.Stream, encoder As Imaging.ImageCodecInfo, encoderParams As Imaging.EncoderParameters) SaveImpl(stream, encoder.Clsid, ToNativeEncoderParameters(encoderParams)) End Sub Sub Save(stream As IStream, encoder As Imaging.ImageCodecInfo, encoderParams As Imaging.EncoderParameters) SaveImpl(stream, encoder.Clsid, ToNativeEncoderParameters(encoderParams)) End Sub */ Private Static Function ToNativeEncoderParameters(encoderParams As Imaging.EncoderParameters) As *Gdiplus.EncoderParameters If ActiveBasic.IsNothing(encoderParams) Then ToNativeEncoderParameters = 0 Else ToNativeEncoderParameters = encoderParams.Params End If End Function Sub SaveImpl(filename As PCWSTR, ByRef clsidEncoder As CLSID, encoderParams = 0 As *Gdiplus.EncoderParameters) SetStatus(GdipSaveImageToFile(nativeImage, filename, clsidEncoder, encoderParams)) End Sub /* Sub SaveImpl(stream As IStream, ByRef clsidEncoder As CLSID, encoderParams = 0 As *Gdiplus.EncoderParameters) SetStatus(GdipSaveImageToStream(stream, clsidEncoder, encoderParams) End Sub */ Public Sub SaveAdd(encoderParams As Imaging.EncoderParameters) SetStatus(GdipSaveAdd(nativeImage, ByVal ToNativeEncoderParameters(encoderParams))) End Sub Sub SaveAdd(newImage As Image, encoderParams As Imaging.EncoderParameters) If ActiveBasic.IsNothing(newImage) Then Throw New ArgumentNullException("newImage") End If SetStatus(GdipSaveAddImage(nativeImage, newImage.NativeImage, ByVal ToNativeEncoderParameters(encoderParams))) End Sub Function PhysicalDimension() As SizeF With PhysicalDimension SetStatus(GdipGetImageDimension(nativeImage, .Width, .Height)) End With End Function /* Function GetBounds(pageUnit As GraphicsUnit) As RectangleF SetStatus(GdipGetImageBounds(nativeImage, pageUnit, GetBounds)) End Function */ Function Width() As DWord SetStatus(GdipGetImageWidth(nativeImage, Width)) End Function Function Height() As DWord SetStatus(GdipGetImageHeight(nativeImage, Height)) End Function Function Size() As Size Size.Width = This.Width Size.Height = This.Height End Function Function HorizontalResolution() As Single SetStatus(GdipGetImageHorizontalResolution(nativeImage, HorizontalResolution)) End Function Function VerticalResolution() As Single SetStatus(GdipGetImageVerticalResolution(nativeImage, VerticalResolution)) End Function Function Flags() As DWord SetStatus(GdipGetImageFlags(nativeImage, Height)) End Function /* Status GetRawFormat(OUT GUID *format); */ ' Function PixelFormat() As Imaging.PixelFormat ' SetStatus(GdipGetImagePixelFormat(nativeImage, PixelFormat)) ' End Function ' Palette - GetPaletteSize/GetPalette/SetPalette /* Image* GetThumbnailImage(IN UINT thumbWidth, IN UINT thumbHeight, IN GetThumbnailImageAbort callback = NULL, IN VOID* callbackData = NULL); */ ' FrameDimensionsList - GetFrameDimensionsCount/GetFrameDimensionsList ' GetFrameCount ' SelectActiveFrame Sub RotateFlip(rotateFlipType As RotateFlipType) SetStatus(GdipImageRotateFlip(nativeImage, rotateFlipType)) End Sub ' PropertyIdList - GetPropertyCount/GetPropertyIdList ' GetPropertyItem - GetPropertyItemSize/GetPropertyItem ' PropertyItems - GetPropertySize/GetAllPropertyItems ' RemovePropertyItem ' SetPropertyItem ' GetEncoderParameterList - GetEncoderParameterList/GetEncoderParameterListSize Private nativeImage As *GpImage End Class Namespace Imaging Class ImageCodecInfo Public Sub ImageCodecInfo(ByRef nativeImageCodecInfo As Gdiplus.ImageCodecInfo) ici = nativeImageCodecInfo End Sub Function Clsid() As CLSID Clsid = ici.FormatID End Function Function FormatID() As GUID FormatID = ici.FormatID End Function Function CodecName() As String CodecName = New String(ici.CodecName) End Function Function DllName() As String DllName = New String(ici.DllName) End Function Function FormatDescription() As String FormatDescription = New String(ici.FormatDescription) End Function Function FilenameExtension() As String FilenameExtension = New String(ici.FilenameExtension) End Function ' Function Flags() As ImageCodecFlags ' Flags = ici.Flags ' End Function Function Version() As DWord Version = ici.Version End Function ' SignaturePatterns ' SignatureMasks Static Function GetImageDecoders() As Collections.Generic.IEnumerable Dim num As DWord Dim bufSize As DWord SetStatus(GdipGetImageDecodersSize(num, bufSize)) Dim pici = GC_malloc_atomic(bufSize) As *Gdiplus.ImageCodecInfo SetStatus(GdipGetImageDecoders(num, bufSize, pici)) GetImageDecoders = ImageCodecInfoPtrToEnumerable(pici, num) End Function Static Function GetImageEncoders() As Collections.Generic.IEnumerable Dim num As DWord Dim bufSize As DWord SetStatus(GdipGetImageEncodersSize(num, bufSize)) Dim pici = GC_malloc_atomic(bufSize) As *Gdiplus.ImageCodecInfo SetStatus(GdipGetImageEncoders(num, bufSize, pici)) GetImageEncoders = ImageCodecInfoPtrToEnumerable(pici, num) End Function Private Static Function ImageCodecInfoPtrToEnumerable(pici As *Gdiplus.ImageCodecInfo, n As DWord) As Collections.Generic.IEnumerable Dim l = New Collections.Generic.List(n) Dim i As DWord For i = 0 To ELM(n) l.Add(New ImageCodecInfo(pici[i])) Next Dim il = l As Collections.Generic.IList ImageCodecInfoPtrToEnumerable = il End Function ici As Gdiplus.ImageCodecInfo End Class Class ImageFormat Public Function Guid() As GUID Guid = guid End Function Override Function Equals(y As Object) As Boolean If This.GetType().Equals(y.GetType()) Then Dim yi = y As ImageFormat Equals = IsEqualGUID(This.guid, yi.guid) As Boolean Else Equals = False End If End Function Override Function GetHashCode() As Long GetHashCode = _System_HashFromGUID(guid) End Function Static Function MemoryBmp() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatMemoryBMP) End Function Static Function Bmp() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatBMP) End Function Static Function Emf() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatEMF) End Function Static Function Wmf() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatWMF) End Function Static Function Jpeg() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatJPEG) End Function Static Function Png() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatPNG) End Function Static Function Gif() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatGIF) End Function Static Function Tiff() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatTIFF) End Function Static Function Exif() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatEXIF) End Function Static Function Icon() As ImageFormat Return New ImageFormat(Gdiplus.ImageFormatIcon) End Function Private Sub ImageFormat(ByRef codecGuid As GUID) guid = codecGuid End Sub guid As GUID End Class Class EncoderParameters Public Sub EncoderParameters() init(1) End Sub Sub EncoderParameters(n As Long) init(n) End Sub Function Params() As *EncoderParameter Params = eps->Parameter End Function Private Sub init(n As Long) Dim size = SizeOf (Gdiplus.EncoderParameters) + SizeOf (EncoderParameter) * n eps = GC_malloc(size) ZeroMemory(eps, size) eps->Count = n End Sub eps As *Gdiplus.EncoderParameters End Class End Namespace End Namespace End Namespace Namespace Gdiplus Type ImageCodecInfo Clsid As CLSID FormatID As GUID CodecName As PCWSTR DllName As PCWSTR FormatDescription As PCWSTR FilenameExtension As PCWSTR MimeType As PCWSTR Flags As DWord Version As DWord SigCount As DWord SigSize As DWord SigPattern As *Byte SigMask As *Byte End Type Type Align(8) EncoderParameters Count As DWord Parameter[0] As System.Drawing.Imaging.EncoderParameter End Type End Namespace