delphi で記述されているが、他の言語でも概念は同じはず。 元の色を赤とする。 赤→青 procedure TForm1.Button2Click(Sender: TObject); var i: Integer; c: TColor; r,g,b: byte; x,y: integer; bmp: TBitmap; begin bmp:=TBitmap.Create; try for i:=1 to 6 do begin bmp.LoadFromFile('G:\Inetpub\wwwroot\img\3594\tp_0'+IntToStr(i)+'.bmp'); bmp.PixelFormat:=pf24bit; for y:=0 to bmp.Height-1 do begin for x:=0 to bmp.Width-1 do begin c:=bmp.Canvas.Pixels[x,y]; r:=c and $FF; g:=(c and $FF00) div 256; b:=(c and $FF0000) div(256*256); c:=b+(g*256)+(r*256*256); bmp.Canvas.Pixels[x,y]:=c; end; end; bmp.SaveToFile('G:\Inetpub\wwwroot\img\3594\tp_02-0'+IntToStr(i)+'.bmp'); end; finally bmp.Free; end; end; 赤→緑 procedure TForm1.Button1Click(Sender: TObject); var i: Integer; c: TColor; r,g,b: byte; x,y: integer; bmp: TBitmap; begin bmp:=TBitmap.Create; try for i:=1 to 6 do begin bmp.LoadFromFile('G:\Inetpub\wwwroot\img\3594\tp_0'+IntToStr(i)+'.bmp'); bmp.PixelFormat:=pf24bit; for y:=0 to bmp.Height-1 do begin for x:=0 to bmp.Width-1 do begin c:=bmp.Canvas.Pixels[x,y]; r:=c and $FF; g:=(c and $FF00)div 256; b:=(c and $FF0000)div(256*256); c:=g+(r*256)+(b*256*256); bmp.Canvas.Pixels[x,y]:=c; end; end; bmp.SaveToFile('G:\Inetpub\wwwroot\img\3594\tp_01-0'+IntToStr(i)+'.bmp'); end; finally bmp.Free; end; end; 赤→紫 procedure TForm1.Button3Click(Sender: TObject); var i: Integer; c: TColor; r,g,b: byte; x,y: integer; bmp: TBitmap; begin bmp:=TBitmap.Create; try for i:=1 to 6 do begin bmp.LoadFromFile('G:\Inetpub\wwwroot\img\3594\tp_0'+IntToStr(i)+'.bmp'); bmp.PixelFormat:=pf24bit; for y:=0 to bmp.Height-1 do begin for x:=0 to bmp.Width-1 do begin c:=bmp.Canvas.Pixels[x,y]; r:=c and $FF; g:=(c and $FF00) div 256; b:=(c and $FF0000) div(256*256); c:=r+(g*256)+(r*256*256); bmp.Canvas.Pixels[x,y]:=c; end; end; bmp.SaveToFile('G:\Inetpub\wwwroot\img\3594\tp_03-0'+IntToStr(i)+'.bmp'); end; finally bmp.Free; end; end; 赤→灰 procedure TForm1.Button4Click(Sender: TObject); var i: Integer; c: TColor; r,g,b: byte; x,y: integer; bmp: TBitmap; begin bmp:=TBitmap.Create; try for i:=1 to 6 do begin bmp.LoadFromFile('G:\Inetpub\wwwroot\img\3594\tp_0'+IntToStr(i)+'.bmp'); bmp.PixelFormat:=pf24bit; for y:=0 to bmp.Height-1 do begin for x:=0 to bmp.Width-1 do begin c:=bmp.Canvas.Pixels[x,y]; r:=c and $FF; g:=(c and $FF00) div 256; b:=(c and $FF0000) div(256*256); c:=r+(r*256)+(r*256*256); bmp.Canvas.Pixels[x,y]:=c; end; end; bmp.SaveToFile('G:\Inetpub\wwwroot\img\3594\tp_04-0'+IntToStr(i)+'.bmp'); end; finally bmp.Free; end; end; |
delphi >