単純出力( 半透明なし )半透明出力用の背景透明の画像
半透明出力
![]()
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Text
Module MyModule
' ********************************************************
' 画像の上にテキスト
' ********************************************************
Sub Main()
' 文字列の配列
Dim argv As String()
' コマンドラインの取得
argv = System.Environment.GetCommandLineArgs()
' 引数がある場合
if System.Environment.GetCommandLineArgs.Length > 1 then
Console.WriteLine(argv(1))
else
Console.WriteLine("変換するビットマップファイルを指定して下さい")
Return
end if
' ********************************************************
' 単純書き出し
' ********************************************************
' Bitmap をファイルのパスから作成
Dim bmp As New Bitmap(argv(1))
' キャンバス
Dim gra As Graphics = Graphics.FromImage(bmp)
' 書き出すテキストのフォントを作成
Dim myFont As Font = New Font(FontFamily.GenericSansSerif, _
20, FontStyle.Bold)
' 白色で書きだす
Dim myBrush As New SolidBrush(Color.FromArgb(255,255,255))
' アンチエイリアス設定
gra.TextRenderingHint = TextRenderingHint.AntiAliasGridFit
' 書き出し
gra.DrawString( "lightbox", myFont, myBrush, 70, 28 )
bmp.Save((argv(1).Split("."))(0) + "_text1.png", Imaging.ImageFormat.Png)
bmp.Dispose()
' ********************************************************
' 半透明書き出し
' ********************************************************
' Bitmap をファイルのパスから作成
bmp = New Bitmap(argv(1))
' キャンバス
gra = Graphics.FromImage(bmp)
' 同一サイズの Bitmap
Dim bmp4Text As New Bitmap(bmp.Width, bmp.Height)
' キャンバス
Dim gra4Text As Graphics = Graphics.FromImage(bmp4Text)
' 透明ブラシ
Dim myBaseBrush As New SolidBrush(Color.FromArgb(0,0,0,0))
' 塗りつぶし位置
Dim rects As Rectangle() = {New Rectangle(0, 0, bmp4Text.Width, bmp4Text.Height)}
' 塗りつぶして、透明のキャンバスにする
gra4Text.FillRectangles(myBaseBrush, rects)
' アンチエイリアス設定
gra4Text.TextRenderingHint = TextRenderingHint.AntiAliasGridFit
' 書き出し
gra4Text.DrawString( "lightbox", myFont, myBrush, 70, 28 )
' 途中経過
bmp4Text.Save((argv(1).Split("."))(0) + "_text2.png", Imaging.ImageFormat.Png)
' 半透明出力用属性
Dim att As New ImageAttributes
Dim cm As New ColorMatrix
' 半透明
cm.Matrix00 = 1 ' R
cm.Matrix11 = 1 ' G
cm.Matrix22 = 1 ' B
cm.Matrix33 = 0.5F ' A
cm.Matrix44 = 1
att.SetColorMatrix(cm)
' 半透明書き出し
gra.DrawImage( _
bmp4Text, _
New Rectangle(0, 0, bmp.Width, bmp.Height), _
0, _
0, _
bmp.Width, _
bmp.Height, _
GraphicsUnit.Pixel, _
att _
)
' 半透明書き出し結果
bmp.Save((argv(1).Split("."))(0) + "_text3.png", Imaging.ImageFormat.Png)
' Bitmap の解放
bmp.Dispose()
End Sub
End Module
|
|
【VB.NET : テクニカルの最新記事】
- VB.net(C#) : Picasa より指定したアルバム内の画像の URL 一覧を取得する
- VB.net(VS2010) で COM へ公開して、WSH(VBScript) で利用する( C# でも同様 )
- VB.net : Picasa にアクセスする為に、Google Data API にログインしてトークンを取得する
- VB.net : Win32API 呼び出し : GetWindowsDirectory
- VB.net と C# における KeyPress イベントの受け取り方
- VB.net : フォーカス イベントの発生順序と注意事項
- VB.net クリップボードの処理 ( C# は注意 )
- VB.net : 自分自身(というか元々プロテクトメソッド)を呼び出す遅延処理用プライベートタイマークラス


半透明出力用の背景透明の画像
半透明出力




