Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim W As Integer
Try
W = CInt(TextBox1.Text)
Catch ex As Exception
MsgBox("サイズが整数ではありません")
Exit Sub
End Try
Dim A As Integer
Try
A = CInt(TextBox2.Text)
Catch ex As Exception
MsgBox("透過度が整数ではありません")
Exit Sub
End Try
Dim R As Integer
Try
R = CInt(TextBox3.Text)
Catch ex As Exception
MsgBox("色Rが整数ではありません")
Exit Sub
End Try
Dim G As Integer
Try
G = CInt(TextBox4.Text)
Catch ex As Exception
MsgBox("色Gが整数ではありません")
Exit Sub
End Try
Dim B As Integer
Try
B = CInt(TextBox5.Text)
Catch ex As Exception
MsgBox("色Bが整数ではありません")
Exit Sub
End Try
If A < 0 Or A > 255 Then
MsgBox("透過度は0から255の範囲にしてください")
Exit Sub
End If
If R < 0 Or R > 255 Then
MsgBox("色Rは0から255の範囲にしてください")
Exit Sub
End If
If G < 0 Or G > 255 Then
MsgBox("色Gは0から255の範囲にしてください")
Exit Sub
End If
If B < 0 Or B > 255 Then
MsgBox("色Bは0から255の範囲にしてください")
Exit Sub
End If
'MsgBox(A.ToString + "," + R.ToString + "," + G.ToString + "," + B.ToString)
Dim C As Color
Try
C = Color.FromArgb(A, R, G, B)
Catch ex As Exception
MsgBox("色が不正です")
Exit Sub
End Try
'PictureBox1に描画
Dim gg As Graphics = PictureBox1.CreateGraphics()
Dim bw = New SolidBrush(Color.White)
gg.FillRectangle(bw, 0, 0, 200, 200)
Dim i, j, k As Integer
Dim bg = New SolidBrush(Color.LightGray)
k = 1
For i = 0 To 6
For j = 0 To 6
If k = 1 Then
gg.FillRectangle(bg, 20 * i, 20 * j, 20, 20)
End If
k = k * -1
Next
Next
'半透明のブラシを作成する
Dim br = New SolidBrush(C)
gg.FillRectangle(br, 30, 30, 80, 80)
gg.Dispose()
'Bitmapを作成する
Dim bmp As New Bitmap(W, W)
Dim gb As Graphics = Graphics.FromImage(bmp)
gb.FillRectangle(br, 0, 0, W, W)
gb.Dispose()
'PNG形式でMemoryStreamに保存しBase64にエンコードする
Dim ms As New IO.MemoryStream()
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Dim buffer As Byte() = ms.ToArray
Dim base64String As String = Convert.ToBase64String(buffer)
TextBox6.Text = base64String
'PNG形式でファイルに保存する
If CheckBox1.Checked Then
SaveFileDialog1.Filter = "png|*.png"
If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Try
bmp.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If
End If
bmp.Dispose()
End Sub
End Class
|