|
아마도 동적 어레이를 안써서 억세스 에러가 나는것 같은데요 ..
어찌해 주어야 할까요? 속도는 중요하지 않아서 pixel 을 썼습니다.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Bmp2Raw("c:\\g512x512.bmp", "c:\\zzz.raw");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Bmp2Raw(WideString Bmp_name, WideString Raw_name)
{
TFileStream *fs;
long glength;
fs = new TFileStream(Raw_name, fmCreate);
Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
Byte *ptr;
Byte *gray;
try
{
pBitmap->LoadFromFile(Bmp_name);
glength=(pBitmap->Width+1)*(pBitmap->Height+1);
long k=0;
for (int y = 0; y < 100; y++)
{
for (int x = 0; x < pBitmap->Width; x++)
{
k+=1;
gray[k]=(Byte)(0.3*GetRValue(pBitmap->Canvas->Pixels[x][y])+\
0.6*GetGValue(pBitmap->Canvas->Pixels[x][y])+\
0.1*GetBValue(pBitmap->Canvas->Pixels[x][y]));
} //for
} // for
fs->Write(gray, glength);
} // try
catch (...)
{
ShowMessage("Could not load or alter bitmap");
}
delete pBitmap;
ShowMessage("OK");
delete gray;
delete fs;
|