source: trunk/ab5.0/ablib/src/Classes/System/Drawing/Bitmap.ab@ 704

Last change on this file since 704 was 704, checked in by イグトランス (egtra), 15 years ago

Bitmapクラスの追加
(#242)

File size: 6.3 KB
Line 
1' Classes/System/Drawing/Bitmap.ab
2
3Namespace System
4Namespace Drawing
5
6Class Bitmap
7 Inherits Image
8Public
9 Sub Bitmap(native As *GpBitmap)
10 Image(native As *GpImage)
11 End Sub
12
13 Sub Bitmap(filename As String, useEmbeddedColorManagement = False As Boolean)
14 Image(CreateBitmapFromFile(ToWCStr(filename), useEmbeddedColorManagement) As *GpImage)
15 End Sub
16
17 Sub Bitmap(filename As PCWSTR, useEmbeddedColorManagement = False As Boolean)
18 Image(CreateBitmapFromFile(filename, useEmbeddedColorManagement) As *GpImage)
19 End Sub
20
21 Sub Bitmap(stream As IO.Stream, useEmbeddedColorManagement = False As Boolean)
22 Image(CreateBitmapFromABStream(stream, useEmbeddedColorManagement) As *GpImage)
23 End Sub
24
25 Sub Bitmap(stream As IStream, useEmbeddedColorManagement = False As Boolean)
26 Image(CreateBitmapFromStream(stream, useEmbeddedColorManagement) As *GpImage)
27 End Sub
28
29 Sub Bitmap(width As Long, height As Long, stride As Long, format As Imaging.PixelFormat, scan0 As *Byte)
30 Image(CreateBitmapFromScan0(width, height, stride, format, scan0) As *GpImage)
31 End Sub
32
33 Sub Bitmap(width As Long, height As Long, format /*= Imaging.PixelFormat.Format32bppARGB*/ As Imaging.PixelFormat)
34 Image(CreateBitmapFromScan0(width, height, 0, format, 0) As *GpImage)
35 End Sub
36
37 Sub Bitmap(width As Long, height As Long, target As Graphics)
38 Image(CreateBitmapFromGraphics(width, height, target) As *GpImage)
39 End Sub
40
41 Sub Bitmap(src As Image)
42/*
43 Image(CreateBitmapFromScan0(src.Width, src.Height, 0, src.PixelFormat, 0) As *GpImage)
44 Dim g = Graphics.FromImage(This)
45 g.DrawImage(src)
46 g.Dispose()
47*/
48 Throw New NotImplementedException
49 End Sub
50
51' Sub Bitmap(src As Image, size As Size)
52' Sub Bitmap(src As Image, width As Long, height As Long)
53Private
54 Static Function CreateBitmapFromFile(filename As PCWSTR, useEmbeddedColorManagement As Boolean) As *GpBitmap
55 If useEmbeddedColorManagement Then
56 SetStatus(GdipCreateBitmapFromFileICM(filename, CreateBitmapFromFile))
57 Else
58 SetStatus(GdipCreateBitmapFromFile(filename, CreateBitmapFromFile))
59 End If
60 End Function
61
62 Static Function CreateBitmapFromStream(stream As IStream, useEmbeddedColorManagement As Boolean) As *GpBitmap
63/*
64 If useEmbeddedColorManagement Then
65 SetStatus(GdipCreateBitmapFromStreamICM(stream, CreateBitmapFromStream))
66 Else
67 SetStatus(GdipCreateBitmapFromStream(stream, CreateBitmapFromStream))
68 End If
69*/
70 Throw New NotImplementedException
71 End Function
72
73 Static Function CreateBitmapFromABStream(stream As IO.Stream, useEmbeddedColorManagement As Boolean) As *GpBitmap
74' Dim comStream = ComStreamFromABStream(stream)
75' Try
76' CreateBitmapFromABStream = CreateBitmapFromStream(comStream, useEmbeddedColorManagement)
77' Finally
78' comStream.Release()
79' End Try
80 Throw New NotImplementedException
81 End Function
82
83 Static Function CreateBitmapFromScan0(width As Long, height As Long, stride As Long, format As Imaging.PixelFormat, scan0 As *Byte) As *GpBitmap
84 SetStatus(GdipCreateBitmapFromScan0(width, height, stride, format, scan0, CreateBitmapFromScan0))
85 End Function
86
87 Static Function CreateBitmapFromGraphics(width As Long, height As Long, target As Graphics) As *GpBitmap
88 SetStatus(GdipCreateBitmapFromGraphics(width, height, target.NativeGraphics, CreateBitmapFromGraphics))
89 End Function
90
91Public
92 Function Clone(ByRef rc As Rectangle, format As Imaging.PixelFormat) As Bitmap
93 Dim cloned As *GpBitmap
94 SetStatus(GdipCloneBitmapAreaI(rc.X, rc.Y, rc.Width, rc.Height, format, NativeBitmap, cloned))
95 Try
96 Clone = New Bitmap(cloned)
97 Catch e As Exception
98 GdipDisposeImage(cloned)
99 Throw e
100 End Try
101 End Function
102
103 Function Clone(ByRef rc As RectangleF, format As Imaging.PixelFormat) As Bitmap
104 Dim cloned As *GpBitmap
105 SetStatus(GdipCloneBitmapArea(rc.X, rc.Y, rc.Width, rc.Height, format, NativeBitmap, cloned))
106 Try
107 Clone = New Bitmap(cloned)
108 Catch e As Exception
109 GdipDisposeImage(cloned)
110 Throw e
111 End Try
112 End Function
113
114 Function LockBits(ByRef rc As Rectangle, flags As DWord, format As Imaging.PixelFormat) As Imaging.BitmapData
115 SetStatus(GdipBitmapLockBits(NativeBitmap, rc, flags, format, LockBits))
116 End Function
117
118 Sub UnlockBits(ByRef lockedBitmapData As Imaging.BitmapData)
119 SetStatus(GdipBitmapUnlockBits(NativeBitmap, lockedBitmapData))
120 End Sub
121
122 Function GetPixel(x As Long, y As Long) As Color
123 SetStatus(GdipBitmapGetPixel(NativeBitmap, x, y, GetPixel))
124 End Function
125
126 Sub SetPixel(x As Long, y As Long, color As Color)
127 SetStatus(GdipBitmapSetPixel(NativeBitmap, x, y, color))
128 End Sub
129
130 Sub SetResolution(xDpi As Single, yDpi As Single)
131 SetStatus(GdipBitmapSetResolution(NativeBitmap, xDpi, yDpi))
132 End Sub
133
134 Static Function FromDirectDrawSurface7(surface As VoidPtr) As Bitmap
135 Dim native As *GpBitmap
136 GdipCreateBitmapFromDirectDrawSurface(surface, native)
137 FromDirectDrawSurface7 = New Bitmap(native)
138 End Function
139
140 Static Function FromBITMAPINFO(ByRef bi As BITMAPINFO, data As VoidPtr) As Bitmap
141 Dim native As *GpBitmap
142 GdipCreateBitmapFromGdiDib(bi, data, native)
143 FromBITMAPINFO = New Bitmap(native)
144 End Function
145
146 Static Function FromHBITMAP(hbm As HBITMAP, hpal As HPALETTE) As Bitmap
147 Dim native As *GpBitmap
148 GdipCreateBitmapFromHBITMAP(hbm, hpal, native)
149 FromHBITMAP = New Bitmap(native)
150 End Function
151
152 Static Function FromHICON(hicon As HICON) As Bitmap
153 Dim native As *GpBitmap
154 SetStatus(GdipCreateBitmapFromHICON(hicon, native))
155 FromHICON = New Bitmap(native)
156 End Function
157
158 Static Function FromResource(hInstance As HINSTANCE, bitmapName As PCWSTR) As Bitmap
159 Dim native As *GpBitmap
160 SetStatus(GdipCreateBitmapFromResource(hInstance, bitmapName, native))
161 FromResource = New Bitmap(native)
162 End Function
163
164 Static Function FromResource(hInstance As HINSTANCE, bitmapName As String) As Bitmap
165 FromResource = FromResource(hInstance, ToWCStr(bitmapName))
166 End Function
167
168 Function GetHBITMAP(colorBackground = &hff000000 As Color) As HBITMAP
169 SetStatus(GdipCreateHBITMAPFromBitmap(NativeBitmap, GetHBITMAP, colorBackground))
170 End Function
171
172 Function GetHICON() As HICON
173 SetStatus(GdipCreateHICONFromBitmap(NativeBitmap, GetHICON))
174 End Function
175Private
176 Function NativeBitmap() As *GpBitmap
177 NativeBitmap = This.NativeImage As *GpBitmap
178 End Function
179End Class
180
181End Namespace
182End Namespace
Note: See TracBrowser for help on using the repository browser.