Printing pixel values out but the image is overlapping. Image is three times the size it should be

StackOverflow https://stackoverflow.com/questions/21660290

  •  09-10-2022
  •  | 
  •  

سؤال

Good day everyone. I managed to print out pixel values(int from byte) from my fingerprint reader and displaying it as image. The text file that contains the pixel values is triple the size that it should be. And the pictures are overlapping. May I know what's wrong??? Here's the code. By the way the raw image is supposed to be 150K byte (480x320pixel).

According to the specification, the image is 8bit 256grayscale.

I suspect it has something to do with the size of the pBuffer which stores the raw image. Please help, I don't know how to solve this.

I used

 sizeof(pBuffer)

it returns a value of four. And there are four same images overlapping. All i want is one image.

void main()
{
ofstream rawImage("Raw image.txt",ios::out);

 PBYTE pvData = (PBYTE)pBuffer;//pBuffer stores the raw image
byte *bPoint = (byte*) pvData;

byte TempArr[153600];
byte *bTo = TempArr;
int Int32[153600];
memcpy(bTo, bPoint, 153600);
for(int i=0;i<153600;i++)
{

Int32[i] = (int)TempArr[i];
rawImage<<" "<<Int32[i];
}
}
هل كانت مفيدة؟

المحلول 2

Ok. Solved the problem. It is the device datasheet problem. The device specified that it is 480x320 but in the real case it is 320x480. That's what caused the overlapping images. Took so long to solve this problem. And btw thanks guys for trying to help

نصائح أخرى

The code you posted writes a text file containing 150K numbers separated by spaces. If the numbers in decimal form typically have 2 digits, that explains the size of your file.

In case you want to write a binary file (containing 150K bytes), you should

  • Not call it .txt
  • open it with ios::out | ios::binary
  • call the write method for the whole block or the put method for single characters instead of using the formatted output operator <<
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top