Ignore:
Timestamp:
Apr 7, 2009, 9:35:42 PM (15 years ago)
Author:
イグトランス (egtra)
Message:

Imageクラスを追加
(#242)

Location:
trunk/ab5.0/ablib/src/Classes/System/Drawing
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/System/Drawing/Graphics.ab

    r701 r703  
    230230        End If
    231231        Dim graphics = 0 As *GpGraphics
    232         SetStatus(GdipGetImageGraphicsContext(image.nativeImage, graphics))
     232        SetStatus(GdipGetImageGraphicsContext(image.NativeImage, graphics))
    233233        Return New Graphics(graphics)
    234234    End Function
     
    12371237            getNativeImage = 0
    12381238        Else
    1239             getNativeImage = image.nativeImage
     1239            getNativeImage = image.NativeImage
    12401240        End If
    12411241    End Function
  • trunk/ab5.0/ablib/src/Classes/System/Drawing/Image.ab

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

    r700 r703  
    133133    EncoderType As DWord '元はTypeという名前
    134134    Value As VoidPtr
    135 End Type
    136 
    137 Type Align(8) EncoderParameters
    138     Count As DWord
    139     Parameter[0] As EncoderParameter
    140135End Type
    141136
     
    411406Const PropertyTagGpsDestDistRef     = &h0019
    412407Const PropertyTagGpsDestDist        = &h001A
    413 
    414 Type ImageCodecInfo
    415     Clsid As CLSID
    416     FormatID As GUID
    417     CodecName As PCWSTR
    418     DllName As PCWSTR
    419     FormatDescription As PCWSTR
    420     FilenameExtension As PCWSTR
    421     MimeType As PCWSTR
    422     Flags As DWord
    423     Version As DWord
    424     SigCount As DWord
    425     SigSize As DWord
    426     SigPattern As *Byte
    427     SigMask As DWord
    428 End Type
    429408
    430409Enum ColorChannelFlag
Note: See TracChangeset for help on using the changeset viewer.