Home > Back-end >  After use Cimage. Save memory access conflict
After use Cimage. Save memory access conflict

Time:12-11

Using image. Create create bitmap read a BMP image data and want to reoccupy after a certain processing image. Save storage, but if use access memory method to modify the bitmap pixel memory access conflict error will occur and use SetPixelRGB, can use the save to save the picture, but SetPixelRGB too slow, want to ask what method by accessing memory again after the modification of pixels with the save save pictures, the code is as follows:


ReadImage. Create (infoHeader. BiWidth, infoHeader. BiHeight, infoHeader biBitCount, 0).
The FILE * fpIn=fopen (strFilePath, "rb");


BYTE * img=new BYTE [giall];

Fseek (fpIn, fileHeader. BfOffBits SEEK_SET);
Fread (img, sizeof (BYTE), giall, fpIn);

Int r, g, b, avg;
for (int i=0; i for (int j=0; J & lt; InfoHeader. BiHeight; J++)
{
R=(int) img [3 * (infoHeader. BiHeight - 1 - j) * infoHeader biWidth + 3 * I];

G=(int) img [3 * (infoHeader. BiHeight - 1 - j) * infoHeader biWidth + 3 * I + 1);

B=(int) img [3 * (infoHeader. BiHeight - 1 - j) * infoHeader biWidth + I + 3 * 2];
Avg=(r + g + b)/3;
If (avg & gt; 70)
{
Avg=255;
}
The else
{
Avg=0;
}


ReadImage. SetPixelRGB (I, infoHeader. BiHeight - 1 - j, avg, avg, avg);
/* * (pRealData pit + I + j * * BPP)=avg.
* (pRealData pit + I + j * * BPP + 1)=avg.
* (pRealData pit + I + j * * BPP + 2)=avg. */
}

ReadImage. Save (strFilePath1);
ReadImage. Destroy ();
  • Related