procedure TForm1.Button1Click(Sender: TObject);
var
Lo:TBitmap;
I,J:integer;
K1:Longint;
R1,G1,B1,Res:Byte;
begin
Lo:=TBitmap.create;
Lo.Width:=Image1.Width;
Lo.height:=Image1.height;for I:=0 to Image1.Width+1 do
for J:=0 to Image1.Height+1 do
begin
K1:=ColorToRGB(Image1.Canvas.Pixels[I,J]);
R1:=Byte(K1);
G1:=Byte(k1 shr 8);
B1:=Byte(k1 shr 8);
Res:=(R1+G1+B1) div 3;
Lo.Canvas.Pixels[I,J]:=RGB(Res,Res,Res);
end;Image1.Canvas.Draw(0,0,Lo);
Lo.free;
end.
var
Lo:TBitmap;
I,J:integer;
K1:Longint;
R1,G1,B1,Res:Byte;
begin
Lo:=TBitmap.create;
Lo.Width:=Image1.Width;
Lo.height:=Image1.height;for I:=0 to Image1.Width+1 do
for J:=0 to Image1.Height+1 do
begin
K1:=ColorToRGB(Image1.Canvas.Pixels[I,J]);
R1:=Byte(K1);
G1:=Byte(k1 shr 8);
B1:=Byte(k1 shr 8);
Res:=(R1+G1+B1) div 3;
Lo.Canvas.Pixels[I,J]:=RGB(Res,Res,Res);
end;Image1.Canvas.Draw(0,0,Lo);
Lo.free;
end.
创建内存DC CreateDC?
用SelectObject 将位图选入DC
复制你的图片到DC bitblt?显示你创建的位图看看
确定是否用单色方式显示位图
var
Bitmap :TBitmap ;
begin
Bitmap := TBitmap.Create ;
Bitmap.LoadFromFile('原文件');
Bitmap.Mask(clwhite);
Bitmap.PixelFormat := pf1bit ;
bitmap.SaveToFile('目标文件') ;
bitmap.Free ;
end;
BitMap1,BitMap2 : TBitMap;
MyFormat : Word;
begin
BitMap2 := TBitMap.Create;
BitMap1 := TBitMap.Create;
try
BitMap1.LoadFromFile('c:\Program Files\common Files\Borland Shared\Images\Splash\256color\factory.bmp');
BitMap2.Assign(BitMap1); // Copy BitMap1 into BitMap2
BitMap2.Dormant; // Free up GDI resources
BitMap2.FreeImage; // Free up Memory.
Canvas.Draw(20,20,BitMap2); // Note that previous calls don't lose the image BitMap2.Monochrome := true;
Canvas.Draw(80,80,BitMap2);
BitMap2.ReleaseHandle; // This will actually lose the bitmap;
finally
BitMap1.Free;
BitMap2.Free;
end;
end;