|
Bmp2Raw 함수는 이상하게 구성되어 있네요..
아래를 보세요..
곽성주 님이 쓰신 글 :
: 아마도 동적 어레이를 안써서 억세스 에러가 나는것 같은데요 ..
:
: 어찌해 주어야 할까요? 속도는 중요하지 않아서 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; // 선언만 해 놓고 메모리 할당을 안하면 100% 에러 납니다.
: try
: {
: pBitmap->LoadFromFile(Bmp_name);
: glength=(pBitmap->Width+1)*(pBitmap->Height+1); // glength=pBitmap->Width*pBitmap->Height); 이게 맞지 않나요?
--> gray = new Byte[glength]; 로 메모리를 할당 받으세요.
: long k=0;
: for (int y = 0; y < 100; y++) // --> for(int y = 0; y < bBitmap->Height; 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]));
--> k++; //추가..
:
: } //for
: } // for
:
: fs->Write(gray, glength);
: } // try
: catch (...)
: {
: ShowMessage("Could not load or alter bitmap");
: }
: delete pBitmap;
: ShowMessage("OK");
:
: delete gray; // delete[] gray; 로 바꾸세요.
: delete fs;
|