|
void __fastcall TForm2::BitmapToBuff( Graphics::TBitmap *d_Bitmap, unsigned char *d_Buff )
{
unsigned char *tBuff;
int pos;
for(int y = 0; y < m_iTextHeight; y++)
{
tBuff = (unsigned char *) d_Bitmap->ScanLine[y];
pos = m_iTextWidth * 4 * y;
memcpy(d_Buff+pos,tBuff ,((m_iTextWidth)*4));
}
}
Word __fastcall TForm2::TORGB(byte blue, byte green , byte red)
{
return((blue>>3)<<10) | ((green>>3)<<5) | (red>>3);
}
void __fastcall TForm2::Button1Click(TObject *Sender)
{
int a = m_iTextWidth * 4 * m_iTextHeight;
unsigned char *d_Buff = new unsigned char[a];
Graphics::TBitmap *s_Bitmap = new Graphics::TBitmap();
Word *s_Buff = new Word[a];
if(OpenDialog1->Execute() == true)
{
s_Bitmap->LoadFromFile(OpenDialog1->FileName);
}
BitmapToBuff(s_Bitmap,d_Buff);
Graphics::TBitmap *c_Bitmap = new Graphics::TBitmap();
int k = 0;
for(int i = 0;i <a-3; i+=4)
{
s_Buff[k] = TORGB(d_Buff[i],d_Buff[i+1],d_Buff[i+2]);
Memo1->Lines->Add(s_Buff[k]);
k++;
}
Graphics::TBitmap *h_Bitmap = new Graphics::TBitmap();
long int px,py;
PWordArray pbmp;
h_Bitmap->Width = m_iTextWidth;
h_Bitmap->Height = m_iTextHeight;
h_Bitmap->PixelFormat = pf15bit;
int j = 0;
for(int py = 0; py < m_iTextHeight ;py++);
{
pbmp =(PWordArray)h_Bitmap->ScanLine[py];
for(px =0; px < m_iTextWidth;px++)
{
*pbmp[px] = s_Buff[j];<- 이부분에서 메모리 오류가 납니다
j++;
}
}
0번째는 들어가지는데 1 부터 메모리 오류가 나네요 메모리 오류가 안나게 바꾸려면 어떻해 해야 하나요?
|