안녕하세요... 델 전문가님^^
헤헤~~~ 연말 잘 보내시구 계신가요^^
급한 질문이 있어서요^^
저번에 질문하였던 API로.. 이미지 읽어오는 거요.. 대충 짰는데.. 잘 안되네요..
그래서.... 여쭈어 보는 것입니다.
두파일로 Test를 했는데...
nmlog.bmp(256color, size: 41958)이구요
splash.bmp(256color, size: 91080)으로 했는데...
잘 안되네요... nmlog file은 두군데에서 시도 했엇는데
먼저 C Drive아래서 Access violation 에러,
그리고 nmlog.bmp를 델파이 프로젝트 폴더 아래서 했는데 메모리 창이 뜨면서 Error
splash file은 그냥 묵묵 무답... 반응 없음이요....
한번 소스를 봐주시기 부탁 드립니다.
좋은 한해 맞으시구요^^
//*****************************//
// Bitmap Picture //
//*****************************//
//
procedure TfrmBrowser.OnPaintBmp(var Message: TMessage);
var
hPaintDC : HDC;
hMemDC : HDC;
hNewBmp : HBITMAP;
hOldBmp : HBITMAP;
PS : PAINTSTRUCT;
hNewPal : HPALETTE;
hOldPal : HPALETTE;
Bmp : BITMAP;
Rect : TRect;
//begin
//with Message do
// case Msg of
// WM_PAINT:
begin
//hPaintDC := BeginPaint(pboxPic.Canvas.Handle, ps);
hPaintDC := BeginPaint(imgPic.Canvas.Handle, ps);
If( hDibInfo <> null) then
begin
hNewPal := CreateBIPalette(PBITMAPINFOHEADER(@biHeader));
if (hNewPal <> null) then
begin
hNewBmp := DIBToBitmap(hNewPal);
if (hNewBmp <> null) then
begin
hOldPal := SelectPalette(hPaintDC, hNewPal, LongBool(0));
RealizePalette(hPaintDC);
GetObject(hNewBmp, sizeof(BITMAP), @Bmp);
hMemDC := CreateCompatibleDC(hPaintDC);
if (hMemDC <> null) then
begin
hOldBmp := HBITMAP(SelectObject(hMemDC, hPaintDC));
if (bViewMode <> null) then
BitBlt(hPaintDC, 0, 0, Bmp.bmWidth, Bmp.bmHeight,
hMemDC, 0, 0, SRCCOPY)
else
begin
//Rect := pboxPic.ClientRect;
Rect := imgPic.ClientRect;
StretchBlt(hPaintDC, 0, 0, Rect.Right, Rect.Bottom,
hMemDC ,0, 0, Bmp.bmWidth, Bmp.bmHeight, SRCCOPY);
end;
SelectObject(hMemDC, hOldBmp);
DeleteDC(hMemDC);
end;
DeleteObject(hNewBmp);
end;
SelectPalette(hPaintDC, hOldPal, LongBool(0));
DeleteObject(hNewPal);
end;
//EndPaint(pboxPic.Canvas.Handle, PS);
EndPaint(imgPic.Canvas.Handle, PS);
end;
end;
//end;
//end;
// to read the bitmap file
procedure TfrmBrowser.ReadBMPFile(FileName : PChar);
var
hFile : THANDLE;
begin
hFile := CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ,nil,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);
ReadInf(hFile);
LoadBitmapBits(hFile, bfHeader.bfOffBits);
CloseHandle(hFile);
end;
// to read the bitmap file Infomation
procedure TfrmBrowser.ReadInf(hFile : THANDLE);
var
wColors : DWORD;
dwRead : DWORD;
begin
SetFilePointer(hFile, 0, nil, FILE_BEGIN);
ReadFile(hFile, bfHeader, sizeof(BITMAPFILEHEADER), dwRead, nil);
ReadFile(hFile, biHeader, sizeof(BITMAPINFOHEADER), dwRead, nil);
If (hDibInfo <> NULL) then
begin
GlobalUnLock(hDibInfo);
GlobalFree(hDibInfo);
hDibInfo := 0;
end;
wColors := DIBNumColors(@biHeader);
If (hDibInfo = GlobalAlloc(GMEM_MOVEABLE, sizeof(BITMAPFILEHEADER)
+ wColors * sizeof(RGBQUAD))) then
begin
pDibInfo := PBITMAPINFO(GlobalLock(hDibInfo));
pDibInfo^.bmiHeader := biHeader;
ReadFile(hFile, pDibInfo^.bmiColors[0],wColors * sizeof(RGBQUAD),
dwRead,nil);
end;
end;
// to Load the Bitmap file
function TfrmBrowser.LoadBitmapBits(hFile : THANDLE; dwOffBits : DWORD) : THandle;
var
dwSize : DWORD;
dwByteRead : DWORD;
begin
If (biHeader.biCompression = BI_RGB) then
dwSize := bfHeader.bfSize - bfHeader.bfOffBits
else
dwSize := biHeader.biSizeImage;
SetFilePointer(hFile, dwOffBits, nil, FILE_BEGIN);
If (hbitmapBits <> 0) then GlobalFree(hBitmapBits);
hBitmapBits := GlobalAlloc(GMEM_MOVEABLE, dwSize);
lpBitmapBits := PChar(GlobalLock(hbitmapBits));
ReadFile(hFile, lpBitmapBits, dwSize, dwbyteRead, nil);
GlobalUnlock(hBitmapBits);
result := hBitmapBits;
end;
function TfrmBrowser.DIBNumColors(pv : pChar) : Integer;
var
bits : Integer;
lpbi : PBITMAPINFOHEADER;
lpbc : PBITMAPCOREHEADER;
begin
lpbi := PBITMAPINFOHEADER(pv);
lpbc := PBITMAPCOREHEADER(pv);
If (lpbi^.biSize <> sizeof(BITMAPCOREHEADER)) then
begin
If (lpbi^.biClrUsed <> 0) then
begin
result := WORD(lpbi^.biClrUsed);
bits := lpbi^.biBitCount;
end
end
else
begin
bits := lpbc^.bcBitCount;
end;
case bits of
1 : result := 2;
4 : result := 16;
8 : result := 256;
else
result := 0;
end;
end;
// to call the DIBToBitmap
function TfrmBrowser.DIBToBitmap(hNewPal : THANDLE): HBITMAP;
var
lpDIBHdr : PChar;
lpDIBBits : PChar;
hNewBmp : HBITMAP;
hPaintDC : HDC;
hOldPal : HPALETTE;
begin
lpDIBHdr := GlobalLock(hDibInfo);
lpDIBHdr := PChar(hDibInfo);
// to get the array of bit that consist the Real Bitmap.
lpBitmapBits := PChar(GlobalLock(hBitmapBits));
lpDIBBits := lpBitmapBits;
hPaintDC := GetDc(NULL);
if (hPaintDC <> null) then
else
result := NULL;
if (hNewPal <> null) then
else
hOldPal := SelectPalette(hPaintDC, hNewPal, False);
RealizePalette(hPaintDC);
hNewBmp := CreateDIBitmap(hPaintDC,PBITMAPINFOHEADER(lpDIBHdr)^, CBM_INIT,
lpDIBBits, PBITMAPINFO(lpDIBHdr)^, DIB_RGB_COLORS);
if (hNewBmp <> null) then
else
result := NULL;
if (hOldPal <> null) then
else
SelectPalette(hPaintDC, hOldPal, False);
ReleaseDC(NULL, hPaintDC);
GlobalUnlock(hBitmapBits);
GlobalUnlock(hDibInfo);
result := hNewBmp;
end;
function TfrmBrowser.PaletteSize(lpbi: PChar) : WORD;
begin
result := DIBNumColors(lpbi) * sizeof(RGBQUAD);
end;
function TfrmBrowser.FindDIBits(lpbi : PChar) : PChar;
begin
result := lpbi + PaletteSize(lpbi) + DWORD(lpbi);
end;
function TfrmBrowser.CreateBIPalette(lpbi : PBITMAPINFOHEADER) : HPALETTE;
var
lpPal : PLOGPALETTE;
hPaint : THANDLE;
hPal : HPALETTE;
nNumColors : Integer;
i : Integer;
red : BYTE;
green : BYTE;
blue : BYTE;
pRgb : PRGBQUAD;
begin
If lpbi = nil then
result := NULL;
If lpbi^.biSize <> sizeof(BITMAPINFOHEADER) then
result := NULL;
// to exist the table consisted the RGBQUAD after BITMAPINFOHEADER
pRgb := PRGBQUAD(LPSTR(lpbi) + WORD(lpbi^.biSize));
nNumColors := DIBNumColors(PChar(lpbi));
If nNumColors <> null then
begin
hPaint := GlobalAlloc(GHND, sizeof(LOGPALETTE) + nNumColors
* sizeof(PALETTEENTRY));
lpPal := PLOGPALETTE(GlobalLock(hPaint));
If (lpPal = nil) then
result := null;
lpPal^.palNumEntries := nNumColors;
lpPal^.palVersion := $300;
for i := 0 to nNumColors do
begin
lpPal^.palPalEntry[i].peRed := pRgb^.rgbRed;
lpPal^.palPalEntry[i].peGreen := pRgb^.rgbGreen;
lpPal^.palPalEntry[i].peBlue := pRgb^.rgbBlue;
lpPal^.palPalEntry[i].peFlags := BYTE(0);
Inc(pRgb);
end;
hpal := CreatePalette(lpPal^);
GlobalUnlock(hPaint);
GlobalFree(hPaint);
end
else if lpbi^.biBitCount = 24 then
begin
nNumColors := 256;
hPaint := GlobalAlloc(GHND, sizeof(LOGPALETTE) + nNumColors
* sizeof(PALETTEENTRY));
lpPal := PLOGPALETTE(GlobalLock(hPaint));
if (lpPal = nil) then
result := null;
lpPal^.palNumEntries := nNumColors;
lpPal^.palVersion := $300;
red := 0;
green := 0;
blue := 0;
for i := 0 to nNumColors do
begin
lpPal^.palPalEntry[i].peRed := red;
lpPal^.palPalEntry[i].peGreen := green;
lpPal^.palPalEntry[i].peBlue := blue;
lpPal^.palPalEntry[i].peFlags := BYTE(0);
end;
hPal := CreatePalette(lpPal^);
GlobalUnlock(hPaint);
GlobalFree(hPaint);
end;
result := hPal;
end;
end.