[DUG]Image manipulation

Stacey Verner stacey at cjntech.co.nz
Fri Nov 17 08:37:52 NZDT 2006


If the contents of the image is a bitmap then you can use properties of
the images canvas as follows.
 
function TfMain.ChangeColour(AColour: TColor): TColor;
var
  LR, LG, LB: Integer;
begin
  // Break out the colour channels.
  LR := AColour and $0000FF;
  LG := (AColour and $00FF00) shr 8;
  LB := (AColour and $FF0000) shr 16;
  // Swap R and B and put them back to gether again.
  Result := LB
      + (LG shl 8)
      + (LR shl 16);
end;
 
procedure TfMain.ChangeColour;
var
  LCanvas: TCanvas;
  LX, LY: Integer;
begin
  LCanvas := iBitmap.Canvas;
 
  for LY := 0 to iBitmap.Height - 1 do begin
    for LX := 0 to iBitmap.Width - 1 do begin
      LCanvas.Pixels[LX, LY] := ChangeColour(LCanvas.Pixels[LX, LY]);
    end;
  end;
end;
 
Supposedly this is slow and you can use
iBitmap.Picture.Bitmap.Scanline[x], but it is more complicated as you
have to handle different pixel formats.
 
You could also look at the Graphics32 (www.graphics32.org) library which
is nice, easy and fast whith lots of builtin stuff.
 
I have sent you a simple demo project that demonstrates this off list.
 
Stacey
 

________________________________

From: delphi-bounces at ns3.123.co.nz [mailto:delphi-bounces at ns3.123.co.nz]
On Behalf Of John Bird
Sent: Friday, 17 November 2006 00:05
To: 'NZ Borland Developers Group - Delphi List'
Subject: [DUG]Image manipulation


Is there a simple way of altering one colour in an image, eg where there
is a blue  altering the blue to for instance red?
 
Either in a delphi program, or with an image utility.
 
Reason:
I was thinking of making my own LED light, using an image that has
shadows and reflection in it.  I would however like to be able to change
the tone of the image from blue to red to green programmatically, still
keeping the shading and reflections - ie the lighter and darker tones
already in it.
 
something like
 
    ChangeColour(image1,clBlue,clRed);     //swap blue to red
 
 
Even if I have to do it with an image program it would be ok, and load
several different coloured versions of the image, but doing it in the
program with one image would be especially cool.   For instance I know I
can do it with IrfanView - there is an option to switch RGB to GBR and
so on, which achieves the main colour alterations I want, and I can save
several colour versions of the same original image.....
 
 
 

John

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20061117/baedff77/attachment.html


More information about the Delphi mailing list