主要根据二进制的前几个数据来判断
osgEarth/ImageUtils.cpp
osgDB::ReaderWriter*
ImageUtils::getReaderWriterForStream(std::istream& stream) {
// Modified from https://oroboro.com/image-format-magic-bytes/
// Get the length of the stream
stream.seekg(0, std::ios::end);
unsigned int len = stream.tellg();
stream.seekg(0, std::ios::beg);
if (len < 16) return 0;
//const char* data = input.c_str();
// Read a 16 byte header
char data[16];
stream.read(data, 16);
// Reset reading
stream.seekg(0, std::ios::beg);
// .jpg: FF D8 FF
// .png: 89 50 4E 47 0D 0A 1A 0A
// .gif: GIF87a
// GIF89a
// .tiff: 49 49 2A 00
// 4D 4D 00 2A
// .bmp: BM
// .webp: RIFF ???? WEBP
// .ico 00 00 01 00
// 00 00 02 00 ( cursor files )
switch (data[0])
{
case '\xFF':
return (!strncmp((const char*)data, "\xFF\xD8\xFF", 3)) ?

本文详细介绍了如何使用osg库通过分析二进制数据的前几个字节来识别图片类型。内容涵盖了不同图片格式的标识特征及其在二进制数据中的体现。
osg根据二进制数据判断图片类型的方法&spm=1001.2101.3001.5002&articleId=100904460&d=1&t=3&u=99eacf7025434814a1bf571dabec1a88)
3097

被折叠的 条评论
为什么被折叠?



