这是我的源码(请帮忙看看);
Function GetFpImg(FpBmpImg:TBitMap;var FpImg:TFpImage):boolean;overload;
var
BmpInfo:^TBitmapInfo;
BmiHeader:tagBITMAPINFOHEADER;
mDC:HDC;
i,j:integer;
Bmp:TBitMap;
begin
Bmp:=TBitMap.Create;
Bmp.Assign(FpBmpImg);
Bmp.PixelFormat:=pf8bit;
Result:=false;
bmpInfo := AllocMem(SizeOf( TBitmapInfoHeader )+SizeOf(TRGBQuad)*256);
BmiHeader.biSize:=sizeof(BITMAPINFOHEADER);
BmiHeader.biWidth:=IMAGE_WIDTH;
BmiHeader.biHeight:=IMAGE_HEIGHT;
BmiHeader.biPlanes:=1;
BmiHeader.biBitCount:=8;
BmiHeader.biCompression:=0;
BmiHeader.biSizeImage:=0;
BmiHeader.biXPelsPerMeter:=0;
BmiHeader.biYPelsPerMeter:=0;
BmiHeader.biClrUsed:=256;
BmiHeader.biClrImportant:=0;
BmpInfo.BmiHeader:=BmiHeader;
for i:=0 to Image_height do
for j:=0 to image_height do
Fpimg[i,j]:=0;
for i := 0 to 255 do
begin
bmpInfo.bmiColors
.rgbRed := byte(i);
bmpInfo.bmiColors.rgbGreen := byte(i);
bmpInfo.bmiColors.rgbBlue := byte(i);
bmpInfo.bmiColors.rgbReserved :=0 ;
end;
mDC:=GetDC(0);
I:=SetDIBits(mDC,bmp.Handle,0,IMAGE_HEIGHT,@Fpimg,BmpInfo^,DIB_RGB_COLORS);
if I=IMAGE_HEIGHT then Result:=true;
ReleaseDC(0,mDC);
FreeMem( bmpInfo );
bmp.Free;
end;
Function GetFpBmpImg(FpImg:TFpImage):TBitMap;
var
BitmapInfoBitmapInfo;
BmiHeader:tagBITMAPINFOHEADER;
infosize:integer;
I:integer;
begin
Result:=TBitmap.Create;
try
Result.Width:=IMAGE_WIDTH;
Result.Height:=IMAGE_HEIGHT;
Result.PixelFormat:=pf8bit;
infosize:=SizeOf(TBitmapInfoHeader)+SizeOf(TRGBQuad)*256;//对256色
getmem(BitmapInfo,infosize);
for i:=0 to 255 do
begin
BitmapInfo^.bmiColors.rgbBlue:=byte(i);
BitmapInfo^.bmiColors.rgbGreen:=byte(i);
BitmapInfo^.bmiColors.rgbRed:=byte(i);
BitmapInfo^.bmiColors.rgbReserved:=0;
end;
BmiHeader.biSize:=sizeof(BITMAPINFOHEADER);
BmiHeader.biWidth:=IMAGE_WIDTH;
BmiHeader.biHeight:=IMAGE_HEIGHT;
BmiHeader.biPlanes:=1;
BmiHeader.biBitCount:=8;
BmiHeader.biCompression:=0;
BmiHeader.biSizeImage:=0;
BmiHeader.biXPelsPerMeter:=0;
BmiHeader.biYPelsPerMeter:=0;
BmiHeader.biClrUsed:=256;
BmiHeader.biClrImportant:=0;
BitmapInfo.bmiHeader:=BmiHeader;
SetStretchBltMode(Result.Canvas.Handle,COLORONCOLOR);
StretchDIBits(Result.Canvas.Handle,
0,0,
IMAGE_WIDTH,IMAGE_HEIGHT,
0,0,
IMAGE_WIDTH,IMAGE_HEIGHT,
@Fpimg,
BitmapInfo^,
DIB_RGB_COLORS, // wUsage
SRCCOPY);
freemem(BitmapInfo);
except on E:exception do
Result.Free;
end;//end try
end;