Why does BitmapFactory.decodeByteArray return null?

From the documentation:

Returns The decoded bitmap, or null if the image could not be decode.

The bytes involved in the string “test” aren’t a valid bitmap, are they?

If you saved the text “test” in a file called foo.png or foo.jpg etc and tried to open it in Windows, what would you expect the result to be? It would be an error: those bytes simply aren’t a valid image in any known format.

EDIT: I don’t know anything about Android graphics, but your update certainly looks like a much more reasonable way to draw text onto a bitmap.

Leave a Comment