O
onedolph
Unregistered / Unconfirmed
GUEST, unregistred user!
type
TFColor = record b,g,r:Byte end;
PFColor =^TFColor;
procedure Flop(srcBmp,DstBmp:TBitMap);
var
x,y: integer;
incRow,Gap: integer;
DstTmp,SrcTmp: PFColor;
SrcBmInfo,DstBmInfo: TBitmapInfo;
SrcBmHeader,DstBmHeader: TBitmapInfoHeader;
width,height,Size: integer;
SrcBits,DstBits: pointer;
memDC: Integer;
begin
Width:=SrcBmp.Width;
Height:=SrcBmp.Height;
Size:=((Width*3)+(Width mod 4))*Height;
incRow:=((Width*3)+(Width mod 4));
Gap:=Width mod 4;
DstBmp.Assign(SrcBmp);
getMem(srcBits,size);
getMem(DstBits,size);
with SrcbmHeader do begin
biSize:=SizeOf(SrcbmHeader);
biWidth:=Width;
biHeight:=-Height;
biPlanes:=1;
biBitCount:=24;
biCompression:=BI_RGB;
end;
SrcbmInfo.bmiHeader:=srcbmHeader;
with DstbmHeader do begin
biSize:=SizeOf(DstbmHeader);
biWidth:=Width;
biHeight:=-Height;
biPlanes:=1;
biBitCount:=24;
biCompression:=BI_RGB;
end;
DstbmInfo.bmiHeader:=DstbmHeader;
try
memDC:=GetDC(0);
GetDIBits(memDC,srcBmp.Handle,0,Height,srcBits,srcbmInfo,DIB_RGB_COLORS);
DstTmp:=DstBits;
for y:=0 to Height-1 do begin
for x:=0 to Width-1 do begin
SrcTmp:=pointer(integer(SrcBits)+((height-1-y)*IncRow+x*3));
DstTmp^:=SrcTmp^;
Inc(DstTmp);
end;
DstTmp:=Pointer(Integer(DstTmp)+Gap);
end;
SetDIBits(memDC,DstBmp.Handle,0,Height,DstBits,DstbmInfo,DIB_RGB_COLORS);
ReleaseDC(0,memDC);
finally
freemem(SrcBits);
freemem(DstBits);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
bmp:TBitmap;
begin
bmp:=TBitmap.Create;
try
bmp.LoadFromFile('2.bmp');
flop(bmp,Image1.Picture.Bitmap);
finally
bmp.Free;
end;
end;
本意是上下反转图象。
然而在98下正常,在nt4和2000下,却不得到结果,但结果是没有反转,原图给画出来了。
更见鬼的是,即使你把flop中的循环部分注释起来,依然能得到原图。
请高手指点迷津。
TFColor = record b,g,r:Byte end;
PFColor =^TFColor;
procedure Flop(srcBmp,DstBmp:TBitMap);
var
x,y: integer;
incRow,Gap: integer;
DstTmp,SrcTmp: PFColor;
SrcBmInfo,DstBmInfo: TBitmapInfo;
SrcBmHeader,DstBmHeader: TBitmapInfoHeader;
width,height,Size: integer;
SrcBits,DstBits: pointer;
memDC: Integer;
begin
Width:=SrcBmp.Width;
Height:=SrcBmp.Height;
Size:=((Width*3)+(Width mod 4))*Height;
incRow:=((Width*3)+(Width mod 4));
Gap:=Width mod 4;
DstBmp.Assign(SrcBmp);
getMem(srcBits,size);
getMem(DstBits,size);
with SrcbmHeader do begin
biSize:=SizeOf(SrcbmHeader);
biWidth:=Width;
biHeight:=-Height;
biPlanes:=1;
biBitCount:=24;
biCompression:=BI_RGB;
end;
SrcbmInfo.bmiHeader:=srcbmHeader;
with DstbmHeader do begin
biSize:=SizeOf(DstbmHeader);
biWidth:=Width;
biHeight:=-Height;
biPlanes:=1;
biBitCount:=24;
biCompression:=BI_RGB;
end;
DstbmInfo.bmiHeader:=DstbmHeader;
try
memDC:=GetDC(0);
GetDIBits(memDC,srcBmp.Handle,0,Height,srcBits,srcbmInfo,DIB_RGB_COLORS);
DstTmp:=DstBits;
for y:=0 to Height-1 do begin
for x:=0 to Width-1 do begin
SrcTmp:=pointer(integer(SrcBits)+((height-1-y)*IncRow+x*3));
DstTmp^:=SrcTmp^;
Inc(DstTmp);
end;
DstTmp:=Pointer(Integer(DstTmp)+Gap);
end;
SetDIBits(memDC,DstBmp.Handle,0,Height,DstBits,DstbmInfo,DIB_RGB_COLORS);
ReleaseDC(0,memDC);
finally
freemem(SrcBits);
freemem(DstBits);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
bmp:TBitmap;
begin
bmp:=TBitmap.Create;
try
bmp.LoadFromFile('2.bmp');
flop(bmp,Image1.Picture.Bitmap);
finally
bmp.Free;
end;
end;
本意是上下反转图象。
然而在98下正常,在nt4和2000下,却不得到结果,但结果是没有反转,原图给画出来了。
更见鬼的是,即使你把flop中的循环部分注释起来,依然能得到原图。
请高手指点迷津。