Guard some functions against non valid BitmapData

Guard some functions against non valid BitmapData. Guard against some possible null values.