Seeing if graphics has no contents

What is the quickest way to detect whether or not, a picture’s graphics has no contents and is just a blank canvas.

Thanks

First, a picture is never blank. It’s just filled with a color you associate with “blank”. So grab the picture’s RGBSurface and loop through comparing pixels:

[code]dim result as boolean
dim blankColor as color = &c000000FF
dim surface as RGBSurface
dim y, x as integer

result = true
surface = p.RGBSurface
For y As Integer = 0 To p.height - 1
For x As Integer = 0 To p.width - 1
If surf.Pixel(x,y) <> blankColor then
result = false
End if
Next
Next
[/code]
This will probably be fast enough for many use cases and smallish to medium sized pictures. If you need speed, you’ll want to implement this in a plugin where you can take advantage of pointer caching through the loops.

Dont’ forget to exit all of your loops if you find a non-blank pixel.

And if blank is an issue… don’t assume it exists… check if p=nil

The quickest way is don’t create the picture object until you’re ready to draw something in it. If you’re talking about a canvas, the quickest way is to use a picture as backing for the canvas, and don’t create the picture object until you’re ready to draw something. Then you simply test the picture variable for nil.

[quote=41329:@Brad Hutchings]First, a picture is never blank. It’s just filled with a color you associate with “blank”. So grab the picture’s RGBSurface and loop through comparing pixels:

[code]dim result as boolean
dim blankColor as color = &c000000FF
dim surface as RGBSurface
dim y, x as integer

result = true
surface = p.RGBSurface
For y As Integer = 0 To p.height - 1
For x As Integer = 0 To p.width - 1
If surf.Pixel(x,y) <> blankColor then
result = false
End if
Next
Next
[/code]
This will probably be fast enough for many use cases and smallish to medium sized pictures. If you need speed, you’ll want to implement this in a plugin where you can take advantage of pointer caching through the loops.[/quote]
Thankyou very much. With a few tweaks it worked perfectly.