用canvas.pixels来画就行了, 这种方法的缺点是比较慢, 但正好适合你的要求
从底升起, 不过是for循环的起始方向的问题
请看如下代码
var
i,j,k, nRed, nGreen, nBlue: integer;
begin
i:=5, j:=5;
//读像素
nRed := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nGreen := GetGValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nBlue := GetBValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
//写像素
Canvas.Pixels[i+320,j] := RGB(nRed ,nGreen,nBlue);
end;
如何保存为JPG格式
procedure TfrmColor.Button12Click(Sender: TObject);
var
jpg : TJpegImage;
begin
jpg := TJpegImage.Create;
jpg.Assign( image1.picture.bitmap );
// Here you can set the jpg object's properties as compression, size and more
jpg.SaveToFile ( './picture.jpg' );
Application.MessageBox('已经将图片以JPG格式存放在当前目录的picture.jpg文件中', '完成',MB_OK);
jpg.Free;
end;
下面的代码,自己慢慢看吧:
procedure TfrmColor.Button1Click(Sender: TObject);
var
i,j,k : integer;
Source : DWORD;
begin
for i := 0 to min(328 ,Image1.Picture.Width) do
for j :=0 to min(328 ,Image1.Picture.Height) do
begin
// k := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j]))+GetGValue(ColorToRGB(Image1.Canvas.Pixels[i,j]))+GetBValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
// k := k div 3;
Source := ColorToRGB(Image1.Canvas.Pixels[i,j]);
k := Round((0.30 * GetRValue(Source)) +
(0.59 * GetGValue(Source)) +
(0.11 * GetBValue(Source)));
Canvas.Pixels[i+320,j] := RGB(k,k,k);
end;
end;
procedure TfrmColor.Button2Click(Sender: TObject);
begin
close;
end;
procedure TfrmColor.Button3Click(Sender: TObject);
var
i,j,k, nRed, nGreen, nBlue: integer;
begin
for i := 0 to min(328 ,Image1.Picture.Width) do
for j :=0 to min(328 ,Image1.Picture.Height) do
begin
nRed := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
// nGreen := GetGValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nBlue := GetBValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
Canvas.Pixels[i+320,j] := RGB(nRed,0,nBlue);
end;
end;
procedure TfrmColor.Button4Click(Sender: TObject);
var
i,j,k, nRed, nGreen, nBlue: integer;
begin
for i := 0 to min(328 ,Image1.Picture.Width) do
for j :=0 to min(328 ,Image1.Picture.Height) do
begin
// nRed := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nGreen := GetGValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nBlue := GetBValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
Canvas.Pixels[i+320,j] := RGB(0,nGreen,nBlue);
end;
end;
procedure TfrmColor.Button5Click(Sender: TObject);
var
i,j,k, nRed, nGreen, nBlue: integer;
begin
for i := 0 to min(328 ,Image1.Picture.Width) do
for j :=0 to min(328 ,Image1.Picture.Height) do
begin
nRed := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nGreen := GetGValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nBlue := GetBValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
Canvas.Pixels[i+320,j] := RGB(255-nRed,255-nGreen,255-nBlue);
end;
end;
procedure TfrmColor.Button6Click(Sender: TObject);
var
i,j,k, nRed, nGreen, nBlue: integer;
begin
for i := 0 to min(328 ,Image1.Picture.Width) do
for j :=0 to min(328 ,Image1.Picture.Height) do
begin
nRed := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nGreen := GetGValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
// nBlue := GetBValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
Canvas.Pixels[i+320,j] := RGB(nRed,nGreen,0);
end;
end;
procedure TfrmColor.Button7Click(Sender: TObject);
var
i,j,k, nRed, nGreen, nBlue: integer;
begin
for i := 0 to min(328 ,Image1.Picture.Width) do
for j :=0 to min(328 ,Image1.Picture.Height) do
begin
nRed := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nGreen := GetGValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
nBlue := GetBValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
Canvas.Pixels[i+320,j] := RGB(nRed,nBlue, nGreen);
end;
end;