VB.NET質問スレ (Part8) at TECH
[2ch|▼Menu]
448:デフォルトの名無しさん
05/01/09 01:52:21
>>443
GetDCするだけじゃ無理らしくて調べてたら説明するよりコードを書いた方が分かりやすくなったのでサンプルクラスをかいとく。
基本はイメージのサイズ指定してのNewすることで一つ四角を描画、あと任意にDrawRectangleで四角を追加。
FillFloodで指定位置の色の連続している部分を塗りつぶし。Bmpフィールドで描画結果を取得。
本文長杉だそうなのでインデントも無きが如し。
Public Class FillFloodTest
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As IntPtr) As IntPtr
Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal color As Integer, ByVal filltype As Integer) As Boolean
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As IntPtr, ByVal obj As IntPtr) As IntPtr
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal color As Integer) As IntPtr
Private Declare Function DeleteObject  Lib "gdi32" (ByVal obj As IntPtr) As Boolean
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As IntPtr) As Boolean
Public Bmp As Bitmap 'Getのみのプロパティにしたいけど行がもったいないのでフィールド直接Public
Public Sub New(ByVal width As Integer, ByVal height As Integer)
 Bmp = New Bitmap(width, height)
 Clear(Color.Brown) '何となく決めうちで茶色でクリア
 DrawRectangle(Color.Red, 100, 100, 100, 100) '何となく決めうちで初めの四角を描画
End Sub
Public Sub DrawRectangle(ByVal line As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
 Dim g As Graphics = Graphics.FromImage(Bmp)
 Dim p As New Pen(line)
 g.DrawRectangle(p, x, y, width, height)
 p.Dispose()
 g.Dispose()
End Sub
Public Sub Clear(ByVal back As Color)
 Dim g As Graphics = Graphics.FromImage(Bmp)
 g.Clear(back)
 g.Dispose()
End Sub


次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

4948日前に更新/258 KB
担当:undef