晨风资讯网
新闻资讯网络冲浪网页设计网络编程图形图像数据库网络媒体服务器网络安全网站运营软件教程黑客认证Wap技术
教程搜索
教程搜索:
  首页 > 程序开发 > VB/VB.NET > 正文  

VB.NET2005计算图片某一区域的面积
日期:2008-6-27 13:53:27 来源: 作者: 浏览:

VB.NET2005计算图片某一区域的面积
Public Structure PicArea
        Dim x1 As Integer
        Dim y1 As Integer
        Dim x2 As Integer
        Dim y2 As Integer
    End Structure

    Public Function ComputationArea(ByVal img As Image) As PicArea
        Dim fArea As New PicArea
        Dim x1, x2, x3, x4, y1, y2, y3, y4 As Integer
        Dim red, green, blue As Integer
        Dim ColorCenter As Integer
        Dim bmp As New Bitmap(img)
        Dim c As System.Drawing.Color
        c = bmp.GetPixel(4, 4)
        Dim i As Integer = (CInt(c.R) + CInt(c.G) + CInt(c.B)) / 3
        If i > 129 Then
            ColorCenter = 150
        Else
            ColorCenter = 150
        End If
        With bmp
            For y As Integer = 8 To .Height - 8
                For x As Integer = 8 To .Width - 8
                    Dim pixel As System.Drawing.Color
                    pixel = .GetPixel(x, y)
                    red = Math.Abs(CInt(pixel.R))
                    green = Math.Abs(CInt(pixel.G))
                    blue = Math.Abs(CInt(pixel.B))
                    If ColorCenter < 150 Then
                        If red > ColorCenter And green > ColorCenter And blue > ColorCenter Then
                            x1 = x
                            y1 = y
                            GoTo goto1
                        End If
                    Else
                        If red < ColorCenter And green < ColorCenter And blue < ColorCenter Then
                            x1 = x
                            y1 = y
                            GoTo goto1
                        End If
                    End If
                Next
            Next
goto1:
            For x As Integer = 8 To .Width - 8
                For y As Integer = 8 To .Height - 8
                    Dim pixel As System.Drawing.Color
                    pixel = .GetPixel(x, y)
                    red = Math.Abs(CInt(pixel.R))
                    green = Math.Abs(CInt(pixel.G))
                    blue = Math.Abs(CInt(pixel.B))
                    If ColorCenter < 150 Then
                        If red > ColorCenter And green > ColorCenter And blue > ColorCenter Then
                            x2 = x
                            y2 = y
                            GoTo goto2
                        End If
                    Else
                        If red < ColorCenter And green < ColorCenter And blue < ColorCenter Then
                            x2 = x
                            y2 = y
                            GoTo goto2
                        End If
                    End If
                Next
            Next
goto2:
            For y As Integer = .Height - 8 To 8 Step -1
                For x As Integer = .Width - 8 To 8 Step -1
                    Dim pixel As System.Drawing.Color
                    pixel = .GetPixel(x, y)
                    red = Math.Abs(CInt(pixel.R))
                    green = Math.Abs(CInt(pixel.G))
                    blue = Math.Abs(CInt(pixel.B))
                    If ColorCenter < 150 Then
                        If red > ColorCenter And green > ColorCenter And blue > ColorCenter Then
                            x3 = x
                            y3 = y
                            GoTo goto3
                        End If
                    Else
                        If red < ColorCenter And green < ColorCenter And blue < ColorCenter Then
                            x3 = x
                            y3 = y
                            GoTo goto3
                        End If
                    End If
                Next
            Next
goto3:
            For x As Integer = .Width - 8 To 8 Step -1
                For y As Integer = .Height - 8 To 8 Step -1
                    Dim pixel As System.Drawing.Color
                    pixel = .GetPixel(x, y)
                    red = Math.Abs(CInt(pixel.R))
                    green = Math.Abs(CInt(pixel.G))
                    blue = Math.Abs(CInt(pixel.B))
                    If ColorCenter < 150 Then
                        If red > ColorCenter And green > ColorCenter And blue > ColorCenter Then
                            x4 = x
                            y4 = y
                            GoTo goto4
                        End If
                    Else
                        If red < ColorCenter And green < ColorCenter And blue < ColorCenter Then
                            x4 = x
                            y4 = y
                            GoTo goto4
                        End If
                    End If
                Next
            Next
        End With
goto4:
        fArea.x1 = x2
        fArea.y1 = y1
        fArea.x2 = x4
        fArea.y2 = y3
        Return fArea
    End Function


上一篇: VB.NET2005计算图片的颜色信息 下一篇:

VB.NET2005图像的锐化和钝化的计算

返回列表 打印此页 加入收藏 资讯论坛 关闭窗口 点击复制本页地址,发送给QQ/MSN好友
关于我们 - 联系我们 - 版权声明 - 帮助(?) - 广告服务 - 友情链接 - 服务项目 - 人才招聘
2003-2008 版权所有 © 晨风资讯网 未经授权禁止复制或建立镜像
CopyRight 2003-2008 www.Net118.com,All Rights Reserved.Design By ChenFeng Network Studio