aguayro
13th January 2012, 22:43
Hi, first thing, i'm a very beginner programmer so please be patient with me and sorry for offensive coding practiques :) ( sorry for my english too... )
I'm here because i've been stucked about 24hours trying to extract a png from a bigger file, i've tryed a lot of things, QByteArrays, char arrays, pointers, QBuffers, etc... but all without sucess.
here is my code now ( it's changed a lot of times.... )
filename is a QString with the filename and path, its ok, i've checked it, same with the offsets, are also checked.
quint32 iconSize;
QFile iconFile( filename );
iconFile.open( QFile::ReadOnly );
QDataStream iconStream( &iconFile );
iconFile.seek(0x1712);
iconStream >> iconSize;
iconFile.seek(0x1716);
char *iconData = new char[iconSize];
iconStream.readRawData(iconData, iconSize);
iconFile.close();
QFile test("test.png");
test.open( QIODevice::WriteOnly );
QDataStream out( &test );
out.writeRawData(iconData, iconSize);
delete[] iconData;
test.close();
basically, i try to access the file, go to size offset to get the size for the char array, so i can read the exact size of the image with readRawData, then, save it into a test file, but fails,
probbably i'm doign a lot of thigs wrong, if anybody could help me i'd be very thankful.
The test.png file size its ok ( 8.124 bytes ), but its ungrecognizable, corrupt data or something, the win7 image viewer says "Image is corrput or too big",
Thanks.
I'm here because i've been stucked about 24hours trying to extract a png from a bigger file, i've tryed a lot of things, QByteArrays, char arrays, pointers, QBuffers, etc... but all without sucess.
here is my code now ( it's changed a lot of times.... )
filename is a QString with the filename and path, its ok, i've checked it, same with the offsets, are also checked.
quint32 iconSize;
QFile iconFile( filename );
iconFile.open( QFile::ReadOnly );
QDataStream iconStream( &iconFile );
iconFile.seek(0x1712);
iconStream >> iconSize;
iconFile.seek(0x1716);
char *iconData = new char[iconSize];
iconStream.readRawData(iconData, iconSize);
iconFile.close();
QFile test("test.png");
test.open( QIODevice::WriteOnly );
QDataStream out( &test );
out.writeRawData(iconData, iconSize);
delete[] iconData;
test.close();
basically, i try to access the file, go to size offset to get the size for the char array, so i can read the exact size of the image with readRawData, then, save it into a test file, but fails,
probbably i'm doign a lot of thigs wrong, if anybody could help me i'd be very thankful.
The test.png file size its ok ( 8.124 bytes ), but its ungrecognizable, corrupt data or something, the win7 image viewer says "Image is corrput or too big",
Thanks.