- 題名: ピクチャボックスに表示している画像にピクチャにモザイク処理を施したい
- 日時: 2008/11/25 21:35:24
- ID: 23422
- この記事の返信元:
- (なし)
- この記事への返信:
- [23423] Re[1]: ピクチャボックスに表示している画像にピクチャにモザイク処理を施したい2008/11/25 23:20:14
- ツリーを表示
1つの方法として、Bitmapクラスのコンストラクタで画像サイズを指定する方法が使えそうです。
もっと良い方法があるかもしれませんが、とりあえずサンプルを書いてみました。参考になれば幸いです。
' ただのテスト用フォーム
Public Class MosaicTestForm
Inherits Form
Dim PictureBox1 As New PictureBoxMosaic
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Me.Text = Me.GetType.Name
' PictureBoxを初期化する
With Me.PictureBox1
.Dock = DockStyle.Fill
.BorderStyle = BorderStyle.Fixed3D
.SizeMode = PictureBoxSizeMode.Zoom
End With
Me.Controls.Add(Me.PictureBox1)
MyBase.OnLoad(e)
End Sub
Protected Overrides Sub OnShown(ByVal e As System.EventArgs)
' 画像ファイルを選択して表示する
Using ofd As New OpenFileDialog
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.PictureBox1.Image = Image.FromFile(ofd.FileName)
End If
End Using
MyBase.OnShown(e)
End Sub
End Class
' モザイク表示機能を持つPictureBox
Public Class PictureBoxMosaic
Inherits PictureBox
' 非モザイク画像を保持するためのフィールド
Dim m_saveimage As Image = Nothing
' モザイク表示中ならTrue
Dim m_isinmosaic As Boolean = False
' モザイク表示中ならTrue
Public Property IsInMosaic() As Boolean
Get
Return Me.m_isinmosaic
End Get
Set(ByVal value As Boolean)
Me.m_isinmosaic = value
If Me.Image Is Nothing Then Return
If value = True Then
' 画像を保存して、モザイク画像(30x30ピクセル)を表示する
Me.m_saveimage = Me.Image
Me.Image = New Bitmap(Me.Image, 30, 30)
Else
If Me.m_saveimage Is Nothing Then Return
' モザイク画像を破棄して画像を元に戻す
If Me.Image IsNot Nothing Then
Me.Image.Dispose()
End If
Me.Image = Me.m_saveimage
End If
End Set
End Property
Protected Overrides Sub OnDoubleClick(ByVal e As System.EventArgs)
' とりあえず、DoubleClickでモザイク表示を切り替える
Me.IsInMosaic = Not Me.IsInMosaic
MyBase.OnDoubleClick(e)
End Sub
End Class
分類:[.NET]
VB2005
ピクチャボックスに表示している画像にピクチャにモザイク処理を施したいのですが、
方法がわかりません。
そもそもモザイク処理というのは自分でロジックを書かなければならないのでしょうか。
その場合、どのような処理、手順で行えばよろしいのでしょうか
よろしくお願い致します。