I have a problem with this function. The result it's giving doesn't match the original data. I can't find the cause of the problem. Encoding and decoding png works fine, but as i save and load the pixels raw data between encoding, it cannot be read.
#include <stdio.h>
#include <tchar.h>
#include "lodepng.h"
void ProcessImage(const char* scrPath, const char* tmpPath, const char* dstPath)
{
unsigned error;
unsigned char* pixelRaw;
unsigned width, height;
//load png
error = lodepng_decode32_file(&pixelRaw, &width, &height, scrPath);
if(error)
printf("error %u: %s\n", error, lodepng_error_text(error));
//save pixels raw to file
ofstream* _stream = new ofstream(tmpPath, ios::out|ios::binary);
_stream->write(reinterpret_cast<const char*>(&pixelRaw), width * height);
_stream->close();
delete _stream;
char* pixelRawTmp;
unsigned char* pixelRaw2;
// load pixels raws from file
ifstream* _stream2 = new ifstream(tmpPath, ios::in|ios::binary);
_stream2->read(pixelRawTmp,width*height);
pixelRaw2 = reinterpret_cast<unsigned char*>(pixelRawTmp);
delete _stream2;
// saving png
error = lodepng_encode32_file(dstPath, pixelRaw2, width, height);
if(error)
printf("error %u: %s\n", error, lodepng_error_text(error));
free(pixelRaw);
free(pixelRawTmp);
free(pixelRaw2);
}