How to tell if a bitmap is empty

If I run the following commands to create a new bitmap and copy into it from a source bitmap:


bmp = Bitmap.new(rect.width, rect.height)
bmp.blt(0, 0, source, rect)


is there an easy way to tell if the new bitmap contains anything?  In the case of a tileset that may only be partially filled, I don't want to continue processing if there were no tiles to copy from the source image.



I've done this, but it didn't work (didn't really expect it to, but had to eliminate the possibility):


return if bmp == Bitmap.new(rect.width, rect.height)






Is there any way other than checking every single pixel for a non-zero alpha?


Edit: I've done the check alpha of every pixel method, and it doesn't take nearly as long as I expected it would, so I don't need a quick answer to this, but I'm still going to leave it open to see if there's an easier/faster way, or a default Bitmap method that will save me having to write a 'check alpha of every pixel' if I ever want to do this again.
You can check for empty once when load bitmap with Bitmap.get_pixel (or FileTest.size) and save result into Bitmap.


This code is just an example:

Code:
class Bitmap
	alias original_initialize initialize
	def initialize(*args)
		# this var will contain result
		@empty = true
		
		if args[0].is_a? String
			# when load from file
			check_for_empty(*args)
			original_initialize(*args)
		elsif args[0].is_a? Fixnum
			# when just create new
			original_initialize(*args)
		end
	end
	
	def check_for_empty(*args)
		# check with self.getxy or something else
		# for example: file.size
		filename = args[0]
		exts = [:png,:jpg,:jpeg,:bmp]
		
		exts.each do |ext|
			if FileTest.exist?("#{filename}.#{ext.to_s}")
				filesize = FileTest.size("#{filename}.#{ext.to_s}")
				if filesize > 8 # cause file header can contain 8 bytes
					# you should use a better checking instead
					@empty = false
				else
					@empty = true
				end
			end
		end
		# then return result
		@empty = true
	end
	
	def empty?
		@empty
	end
	
	alias original_clear clear
	def clear
		original_clear
		@empty = true
	end
	# ...
	# and for other draw_*, fill_* methods too
end

Original thread: https://forums.rpgmakerweb.com/threads/how-to-tell-if-a-bitmap-is-empty.55696/