有效的方法来检测,如果一个图像是空方法来、图像、有效

2023-09-04 12:17:14 作者:谁的青春不犯二

我需要一个非常快速的方法来检测,如果图像是空的。即时通讯我的话,那么所有的像素是白色和TRANSPARANT。 这些图像是PNG的。我的当前方法是将它们加载在存储器中的位图,并检查各像素值,但这是方式减缓。 有没有更有效的方法?

这是我目前的code:

 锁定位图位。
    昏暗bmpData作为System.Drawing.Imaging.BitmapData = bmp.LockBits(rectBmp,_
        Drawing.Imaging.ImageLockMode.ReadOnly,bmp.PixelFormat)

    尝试
        昏暗x As中整数
        昏暗y为整数

        对于Y = 0要bmpData.Height  -  1
            对于x = 0到bmpData.Width  -  1
                如果System.Runtime.InteropServices.Marshal.ReadByte(bmpData.Scan0,(bmpData.Stride * Y)+(4 * X)+ 3)&其中;> 0然后
                    返回TRUE
                    退出对于
                结束如果
            下一个
        下一个
    最后
        bmp.UnlockBits(bmpData)
    结束尝试
 

解决方案

当然,由一组量将图像,为每套启动一个新的线程,只检查非空白像素(例如,不是白色/透明)。

创建一个事件,火灾(并设置一个标志)只有一个非空的像素被发现。让每个线程检查这个标志(基本上是一个while循环)。

利用图像处理方法进行瑕疵检测的总结

I need a very fast method to detect if an image is empty. Im my case then all pixels are white and transparant. The images are png's. My current method is to load them in a memory bitmap and check each pixel value, but this is way to slow. Is there a more efficient way?

This is my current code:

'Lock the bitmap bits.  
    Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(rectBmp, _
        Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat)

    Try
        Dim x As Integer
        Dim y As Integer

        For y = 0 To bmpData.Height - 1
            For x = 0 To bmpData.Width - 1
                If System.Runtime.InteropServices.Marshal.ReadByte(bmpData.Scan0, (bmpData.Stride * y) + (4 * x) + 3) <> 0 Then
                    Return True
                    Exit For
                End If
            Next
        Next
    Finally
        bmp.UnlockBits(bmpData)
    End Try

解决方案

Sure, divide the image by a set amount, for each set start a new thread to only check for non blank pixels (eg not white/transparent).

Create an event that fires (and sets a flag) only if a non empty pixel is found. Have each thread to check this flag (basically a while loop).