Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
688 views
in Technique[技术] by (71.8m points)

image - FInd out if PNG is 8 or 24?

Is there a way to find out if a PNG is the 8 or 24 type? Ive tried with windows, fireworks and photoshop but I cant figure this out. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The quickest way is to just peek at bytes 24 and 25 in the PNG file. They contain the bit depth (1, 2, 4, 8, or 16) and color type

  • 0: gray,
  • 2: rgb,
  • 3: indexed (colormapped),
  • 4: gray+alpha, or
  • 6: rgba.

If the bitdepth is 8 and the colortype is 3 you have a PNG8, and if the bitdepth is 8 and colortype is 2 you have a PNG24.

On a *nix platform, the "file" command will do this for you, e.g.,

A PNG8:

glenn.rp> file logo.png
logo.png: PNG image data, 640 x 480, 8-bit colormap, non-interlaced

A PNG24:

glenn.rp> file rose.png
rose.png: PNG image data, 70 x 46, 8-bit/color RGB, non-interlaced

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...