专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 图形/图像

问个简单有关问题

发布时间:2011-06-27 20:40:46 文章来源:www.iduyao.cn 采编人员:星星草
问个简单问题
VB.NET code


    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



以上代码处理图片的光照效果,执行效率不好。
请高手指点下怎样提高效率。

------解决方案--------------------
不太懂,顶贴一下
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: