アプリ版:「スタンプのみでお礼する」機能のリリースについて

以前は出来たんですが、勉強ノートが紛失してしまいました。
ヘルプで調べましたが、なかなか見つからないです。
たとえば、三個の円を描画して、
交わりの部分の色を変更したい。です。

VB2010の無料版です。

「グラフィックス」の質問画像

A 回答 (1件)

' とりあえずいい加減にやった。

質問文中の図と上下逆だったりするので適当にソース弄って調整してください。
' …なんかもっとすっきりしたコード書けそうなんだけどなあ


Option Explicit On
Option Strict On

Imports System



Public Class Q7371104

Public Shared Sub Main()
Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(500,500)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)

'こっちのほうがわかりやすいかなと。
g.Clear(System.Drawing.Color.Black)

Dim path1 As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath()
Dim path2 As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath()
Dim path3 As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath()

path1.AddEllipse(0, 0, 200,200)
path2.AddEllipse(100, 0, 200,200)
'引数は整数らしいのでやむなく。
path3.AddEllipse(50,Convert.ToInt32(50 * Math.Sqrt(3)),200,200)

' Region.Excludeとかやってもいいけど面倒なので。

g.FillPath(New System.Drawing.SolidBrush(System.Drawing.Color.Red),path1)
g.FillPath(New System.Drawing.SolidBrush(System.Drawing.Color.Blue),path2)
g.FillPath(New System.Drawing.SolidBrush(System.Drawing.Color.Green),path3)

Dim r1 As System.Drawing.Region = New System.Drawing.Region(path1)
r1.Intersect(path2)

Dim r2 As System.Drawing.Region = New System.Drawing.Region(path1)
r2.Intersect(path3)

Dim r3 As System.Drawing.Region = New System.Drawing.Region(path2)
r3.Intersect(path3)

Dim r4 As System.Drawing.Region = New System.Drawing.Region(path1)
r4.Intersect(path2)
r4.Intersect(path3)

g.FillRegion(New System.Drawing.SolidBrush(System.Drawing.Color.Magenta),r1)
g.FillRegion(New System.Drawing.SolidBrush(System.Drawing.Color.Yellow),r2)
g.FillRegion(New System.Drawing.SolidBrush(System.Drawing.Color.Cyan),r3)

g.FillRegion(New System.Drawing.SolidBrush(System.Drawing.Color.White),r4)

g.Save()

'ファイル名とかはお好みでどうぞ
bmp.Save("D:\test.bmp")
End Sub
End Class
    • good
    • 0
この回答へのお礼

ん。早い回答ありがとーございます。
先生ですか?学生さん?

素晴らしいですね。

お礼日時:2012/03/19 16:55

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!