本文整理汇总了C++中BinaryReader::seek方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryReader::seek方法的具体用法?C++ BinaryReader::seek怎么用?C++ BinaryReader::seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryReader
的用法示例。
在下文中一共展示了BinaryReader::seek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool BmpImage::init()
{
initValuesToDefault();
BinaryReader* reader = new BinaryReader(this->image);
reader->reset();
/* read the file data header */
// read the type of the file
reader->seek(FILE_TYPE_OFFSET);
fileType = reader->readWord();
switch (fileType)
{
case BMPBITMAP:
break;
case BMPARRAY:
case BMPCLRICON:
case BMPCLRPOINTER:
case BMPICON:
case BMPPOINTER:
return false;
default:
{
fileType = NOT_BMP; // exception should be thrown
return false;
}
}
// read the file size in bytes
fileSize = reader->readDword();
// read the two hot spots, reserved 1 & reserved 2
Xhot = reader->readWord();
Yhot = reader->readWord();
bitmapOffset = reader->readDword();
/* read the bitmap header now */
headerSize = reader->readDword();
if (headerSize < BMPOLDANYHDRSIZE ||
(headerSize > BMPNEWOS2HDRSIZE && headerSize != BMPNEWWINV4HDRSIZE))
{
fileType = NOT_BMP; // exception should be thrown
return false;
}
// read the rest of the header and the palette if any
if (headerSize == BMPOLDANYHDRSIZE) // we have an old BMP file format
{
version = BMPOLD;
width = (word) reader->readWord();
height = (word) reader->readWord();
planes = reader->readWord();
bitsPerPixel = reader->readWord();
if (bitsPerPixel != 1 || bitsPerPixel != 4 || bitsPerPixel != 8 ||
bitsPerPixel != 24)
{
fileType = NOT_BMP; // exception should be thrown
return false;
}
colorPaletteSize = bitsPerPixel == 24 ? 0 : 1 << bitsPerPixel;
int numberOfEntries = (bitmapOffset - BMPFILEHDRSIZE -
BMPOLDANYHDRSIZE) / BMPOLDPALETTESIZE;
if (colorPaletteSize != numberOfEntries)
{
fileType = NOT_BMP; // exception should be thrown
return false;
}
// read the palette
if (colorPaletteSize != 0)
{
colorPalette = new unsigned long[colorPaletteSize];
for (int i = 0; i < colorPaletteSize; i++)
{
colorPalette[i] = reader->readRGB();
}
}
bitmapSize = rowBytes() * height;
}
else // new BMP file format
{
switch (headerSize)
{
case BMPNEWWINHDRSIZE:
{
version = BMPWINNEW;
break;
}
case BMPNEWOS2HDRSIZE:
{
version = BMPOS2NEW;
//.........这里部分代码省略.........