efficient way to detect if an image is empty
Posted
by Jos
on Stack Overflow
See other posts from Stack Overflow
or by Jos
Published on 2010-06-02T14:26:29Z
Indexed on
2010/06/02
14:43 UTC
Read the original article
Hit count: 254
Hi,
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
© Stack Overflow or respective owner