问个简单问题

123工艺品 2011-07-02 05:42:49


Private Sub 光照效果ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 光照效果ToolStripMenuItem.Click
'以光照效果显示图像,若按原设计则图片尺寸过大
'Dim MyGraphics As Graphics = Me.PictureBox1.CreateGraphics()
'MyGraphics.Clear(Color.White)
'Dim MyBmp As New Bitmap(Me.PictureBox1.Image,Me.PictureBox1.Width, Me.PictureBox1.Height)
'Dim MyWidth As Integer = MyBmp.Width
'Dim MyHeight As Integer = MyBmp.Height
Try
Dim MyWidth As Integer = PictureBox1.Image.Width
Dim MyHeight As Integer = PictureBox1.Image.Height
Dim MyBmp As New Bitmap(Me.PictureBox1.Image, MyWidth, MyHeight)
Dim MyImage As Bitmap = MyBmp.Clone(New RectangleF(0, 0, _
MyWidth, MyHeight), System.Drawing.Imaging.PixelFormat.DontCare)
'MyCenter图片中心点,发亮此值会让强光中心发生偏移
Dim MyCenter As New Point(MyWidth / 2, MyHeight / 2)
'Radius强光照射面的半径,即”光晕”
Dim Radius As Integer = Math.Min(MyWidth / 2, MyHeight / 2)
For i As Integer = MyWidth - 1 To 1 Step -1
For j As Integer = MyHeight - 1 To 1 Step -1
Dim MyLength As Single = CType(Math.Sqrt(Math.Pow((i - _
MyCenter.X), 2) + Math.Pow((j - MyCenter.Y), 2)), Single)
'如果像素位于”光晕”之内
If (MyLength < Radius) Then
Dim MyColor As Color = MyImage.GetPixel(i, j)
Dim r, g, b As Integer
'220亮度增加常量,该值越大,光亮度越强
Dim MyPixel As Integer = 220.0F * (1.0F - MyLength / Radius)
r = MyColor.R + CType(MyPixel, Integer)
r = Math.Max(0, Math.Min(r, 255))
g = MyColor.G + CType(MyPixel, Integer)
g = Math.Max(0, Math.Min(g, 255))
b = MyColor.B + CType(MyPixel, Integer)
b = Math.Max(0, Math.Min(b, 255))
'将增亮后的像素值回写到位图
Dim MyNewColor As Color = Color.FromArgb(255, r, g, b)
MyImage.SetPixel(i, j, MyNewColor)
End If
Next
' MyGraphics.DrawImage(MyImage, New Rectangle(0, 0, MyWidth, MyHeight))
Next
Me.PictureBox1.Image = MyImage
Catch ex As Exception
MessageBox.Show(ex.Message, "信息提示", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub


以上代码处理图片的光照效果,执行效率不好。
请高手指点下怎样提高效率。
...全文
46 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bios8086 2011-07-02
  • 打赏
  • 举报
回复
LZ 你提问别一上来就搞代码!请你描述下你的问题!
sunnywish 2011-07-02
  • 打赏
  • 举报
回复
不太懂,顶贴一下
bios8086 2011-07-02
  • 打赏
  • 举报
回复
VB的代码?

4,448

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧