首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

问个简单有关问题

2012-02-09 
问个简单问题VB.NET codePrivate Sub 光照效果ToolStripMenuItem_Click(ByVal sender As System.Object, B

问个简单问题

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


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

[解决办法]
不太懂,顶贴一下

热点排行