|
■No92068 (kiku さん) に返信
返信、ありがとうございます。
紹介いただいたURL、参考になりました。
FrameRgn APIであっさり描画できました。
画像系はあまりやったことがないので自信ないですが、
後の人の為に実験したコードを置いておきます。
Regionのハンドル解放がReleaseHrgnを使ってますが
DeleteObjectじゃないとダメなのか、ちょっと判りません。
Imports System.Drawing.Drawing2D
Imports System.Runtime.InteropServices
Public Class Form1
Private Enum StockObjects
WHITE_BRUSH = 0
LTGRAY_BRUSH = 1
GRAY_BRUSH = 2
DKGRAY_BRUSH = 3
BLACK_BRUSH = 4
NULL_BRUSH = 5
HOLLOW_BRUSH = NULL_BRUSH
WHITE_PEN = 6
BLACK_PEN = 7
NULL_PEN = 8
OEM_FIXED_FONT = 10
ANSI_FIXED_FONT = 11
ANSI_VAR_FONT = 12
SYSTEM_FONT = 13
DEVICE_DEFAULT_FONT = 14
DEFAULT_PALETTE = 15
SYSTEM_FIXED_FONT = 16
DEFAULT_GUI_FONT = 17
DC_BRUSH = 18
DC_PEN = 19
End Enum
<DllImport("gdi32.dll")>
Private Shared Function FrameRgn(
ByVal hDC As IntPtr,
ByVal hRgn As IntPtr,
ByVal hBrush As IntPtr,
ByVal Width As Integer,
ByVal Height As Integer) As Boolean
End Function
<DllImport("gdi32.dll")>
Private Shared Function GetStockObject(ByVal fnObject As StockObjects) As IntPtr
End Function
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
Using gp1 As New GraphicsPath, gp2 As New GraphicsPath
'楕円のGraphicsPathを2つ作成
gp1.AddEllipse(New Rectangle(10, 10, 300, 300))
gp2.AddEllipse(New Rectangle(160, 10, 300, 300))
Using re1 As New Region(gp1), g = PictureBox1.CreateGraphics
g.SmoothingMode = SmoothingMode.HighQuality
g.PixelOffsetMode = PixelOffsetMode.HighQuality
re1.Union(gp2) '和
Dim re1handle = re1.GetHrgn(g)
Dim hdc = g.GetHdc
Dim ret = FrameRgn(hdc, re1handle, GetStockObject(StockObjects.BLACK_PEN), 3, 3)
re1.ReleaseHrgn(re1handle)
MsgBox(If(ret, "成功", "失敗"))
End Using
End Using
End Sub
End Class
|