开发者

Determine Image Resolution and type (without actually decoding it) in WP7 / Silverlight

How to determine resolution (width x height) and type (gif, jpeg, png, bmp, etc) of an image from a stream (or byte array) without inc开发者_JAVA技巧urring the cost of decoding the entire image?

I know this can be done by just reading the headers. Just wondering if any such code or library already exists.


In addition to the Jpeg info provided in the answer @Leon links to..

GIF files start with the ASCII encoding for "GIF89a" so you can use that signature to determine the file type. Immediately following that are the Width and the Height, both are Int16 values using little-endian byte ordering.

PNG files start with a byte value 89 then the ASCII encoding for "PNG" followed by 4 other bytes. Immediately after that (at offset 8) there are the Width and Height values both 4 bytes wide (I'm not sure of the byte ordering).

BMP files start with the ASCII encoding for "BM". At offset 18 there is an Int32 value specifying width and at offset 22 the height both will use little endian byte ordering.

Armed with this info you should be able to write a little bit of code to read the first 26 bytes of a file stream and from that determine the file type along with the Width and the Height.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜