|
안녕하세요.
빌더6.0으로 그림이 포함한 고지서 출력 프로그램을 짜고 있는데
문제가 발생하여 여러분의 도움을 받으려고 이렇게 글을 올립니다.
고지서에 포함된 TQRImage을 몇 백장 출력할 때 가끔
그림이 출력되지 않는 경우가 발생하고 있습니다.
사진이 빠진 고지서를 다시 출력하면 그때는 이상하게 이미지가 출력되더군요.
그리고 전체 고지서를 다시 출력을 하면 그림이 빠지는 고지서가 달라지더군요.
-------------------------------------
sprintf(szImsiFile, "%s.jpg", szJpgName);
fmGojiReport->qr_ImgCar->Picture->LoadFromFile(szImsiFile);
fmGojiReport->qr_ViolReport->Print();
-------------------------------------
처음 위와 같이 코딩을 했습니다.
그런데 JPEG 파일을 출력할 때 메모리 로드부분에 문제가 있다는
얘기를 듣고 다음과 같이 소스를 변경했는데
-------------------------------------
Graphics::TBitmap *nCurrentBitmap;
TMemoryStream *BMPStrm;
// Load BITMAP from JPEG and Enhance ...
nCurrentBitmap = new Graphics::TBitmap();
BMPStrm = new TMemoryStream;
fmGojiReport->Image1->Picture->LoadFromFile(szImsiFile);
SetJPEGOptions( nCurrentBitmap, fmGojiReport->Image1);
LoadImageFromJPG( BMPStrm, nCurrentBitmap, 0 );
fmGojiReport->qr_imgCarNum->Picture->Bitmap->LoadFromStream(BMPStrm);
delete nCurrentBitmap;
delete BMPStrm ;
fmGojiReport->qr_ViolReport->Print();
-------------------------------------
호출되는 함수들
//---------------------------------------------------------------------------
void __fastcall TfmCarEdit::SetJPEGOptions( Graphics::TBitmap *nCurrentBitmap, TImage *LocalImage )
{
TJPEGImage *jpegimage = dynamic_cast<TJPEGImage *>(LocalImage->Picture->Graphic);
if (jpegimage){
jpegimage->PixelFormat = jf8Bit;
jpegimage->Scale = jsFullSize;
jpegimage->Grayscale = true;
jpegimage->Performance = jpBestQuality;
jpegimage->ProgressiveDisplay = false;
nCurrentBitmap->Assign( jpegimage );
}
}
//---------------------------------------------------------------------------
void __fastcall TfmCarEdit::LoadImageFromJPG( TMemoryStream *BMPStrm, Graphics::TBitmap *nCurrentBitmap, int Option )
{
unsigned char *BmpHead, *Buf_Org;
int iFileHandle, iWidth, iHeight;
char szImsiFile[255]="";
int tmp;
iWidth = nCurrentBitmap->Width;
if ((tmp = iWidth % 4) != 0) iWidth += ( 4 - tmp);
iHeight = nCurrentBitmap->Height;
nCurrentBitmap->SaveToStream(BMPStrm);
BmpHead = new unsigned char[1078 * sizeof(unsigned char)];
Buf_Org = new unsigned char[iWidth*iHeight * sizeof(unsigned char)];
sprintf(szImsiFile, "%s\\1304bmpHead.dat", gszPath);
if ((iFileHandle = FileOpen(szImsiFile, fmOpenRead)) == -1)
{
perror("Error:");
return ;
}
FileRead(iFileHandle, (unsigned char *)BmpHead, (long)1078);
FileClose(iFileHandle);
BMPStrm->Position = 0L;
BMPStrm->ReadBuffer( (unsigned char *)BmpHead, (long)(sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)) );
BMPStrm->Position = 1078L;
BMPStrm->ReadBuffer( (unsigned char *)Buf_Org, (long)(iWidth*iHeight) );
BMPStrm->Position = 0L;
BMPStrm->WriteBuffer(BmpHead, (long)1078);
BMPStrm->Position = 1078L;
BMPStrm->WriteBuffer(Buf_Org, (long)(iWidth*iHeight));
BMPStrm->Position = 0L;
delete BmpHead;
delete Buf_Org;
}
그래도 여전히 빠지는 경우가 발생하고 있습니다.
해결할 수 있는 방법 또는 이렇게 발생되는 원인이라도 알고 계신분은
꼭 도움을 주시길 바라겠습니다.
제가 놓치고 있는 부분이 있는지 아니면 실수를 하고 있는지...
jpg 파일을 로드하는 부분 다음에 sleep()를 줘도 안되고 이거 미치겠습니다.
사진이 안 나올려고 하면 다 안 나오면 다른 방법을 찾아보겠는데
2~3백장 중에 한두장 나올 때도 있고 어느 날은 아주 문제가 없이 잘 나오고
고수님들의 도움을 절실히 구하고 있는 불쌍한 양으로부터...
|