Board index » delphi » how to use bitmaps?

how to use bitmaps?

Hello

I'd like to load a bitmap using a window and then do an analysis of the
pixels by running thru each dot of the bitmap - line by line - and reading
what the red, green and blue values are.  how would I do that?

TIA
flip

 

Re:how to use bitmaps?


Hi!

Try this

  for X:= 0 to Pred(Bitmap.Width) do
    for Y:= 0 to Pred(Bitmap.Height) do
      Bitmap.Canvas.Pixels[X, Y]:= clRed;

    //Peter

Quote
flippit wrote:
> Hello

> I'd like to load a bitmap using a window and then do an analysis of the
> pixels by running thru each dot of the bitmap - line by line - and reading
> what the red, green and blue values are.  how would I do that?

> TIA
> flip

Re:how to use bitmaps?


Load the bitmap into a TImage and then use one of these...

procedure BmpRGB(bmp: TBitmap);
var
  x, y : integer;
  R, G, B : byte;
begin
  Assert(bmp <> nil);

  for y := 0 to bmp.Height -1 do begin

    for x := 0 to bmp.Width -1 do begin
      B := GetBValue(bmp.Canvas.Pixels[x,y]);
      G := GetGValue(bmp.Canvas.Pixels[x,y]);
      R := GetRValue(bmp.Canvas.Pixels[x,y]);

      // do something with R,G,B
    end;

  end;
end;

const
    MaxPixels = 65536; //

type
  TRGBArray = array[0..MaxPixels-1] of TRGBTriple;
  pRGBArray = ^TRGBArray;

procedure ScanLineRGB(bmp: TBitmap);
var
  x, y : integer;
  row :  pRGBArray;
  R, G, B : byte;
begin  
  Assert((bmp <> nil);

  if bmp.PixelFormat = pf24bit then begin

    for y := 0 to bmp.Height -1 do begin
      row := bmp.Scanline[y];

      for x := 0 to bmp.Width -1 do begin
        B := row[x].rgbtBlue;
        G := row[x].rgbtGreen;
        R := row[x].rgbtRed;

        // do something with R,G,B
      end;

    end;
  end else BmpRGB(bmp); // bitmap must be pf24bit for scanline
end;

// ex: ScanLineRGB(Image1.Picture.Bitmap);

Quote
flippit wrote:

> Hello

> I'd like to load a bitmap using a window and then do an analysis of the
> pixels by running thru each dot of the bitmap - line by line - and reading
> what the red, green and blue values are.  how would I do that?

> TIA
> flip

Re:how to use bitmaps?


Thank you Chris and Peter... you're both legends

Quote
Chris Willig <ch...@5thelephant.com> wrote in message

news:3CC8A0ED.8F96E632@5thelephant.com...
Quote
> Load the bitmap into a TImage and then use one of these...

> procedure BmpRGB(bmp: TBitmap);
> var
>   x, y : integer;
>   R, G, B : byte;
> begin
>   Assert(bmp <> nil);

>   for y := 0 to bmp.Height -1 do begin

>     for x := 0 to bmp.Width -1 do begin
>       B := GetBValue(bmp.Canvas.Pixels[x,y]);
>       G := GetGValue(bmp.Canvas.Pixels[x,y]);
>       R := GetRValue(bmp.Canvas.Pixels[x,y]);

>       // do something with R,G,B
>     end;

>   end;
> end;

> const
>     MaxPixels = 65536; //

> type
>   TRGBArray = array[0..MaxPixels-1] of TRGBTriple;
>   pRGBArray = ^TRGBArray;

> procedure ScanLineRGB(bmp: TBitmap);
> var
>   x, y : integer;
>   row :  pRGBArray;
>   R, G, B : byte;
> begin
>   Assert((bmp <> nil);

>   if bmp.PixelFormat = pf24bit then begin

>     for y := 0 to bmp.Height -1 do begin
>       row := bmp.Scanline[y];

>       for x := 0 to bmp.Width -1 do begin
>         B := row[x].rgbtBlue;
>         G := row[x].rgbtGreen;
>         R := row[x].rgbtRed;

>         // do something with R,G,B
>       end;

>     end;
>   end else BmpRGB(bmp); // bitmap must be pf24bit for scanline
> end;

> // ex: ScanLineRGB(Image1.Picture.Bitmap);

> flippit wrote:

> > Hello

> > I'd like to load a bitmap using a window and then do an analysis of the
> > pixels by running thru each dot of the bitmap - line by line - and
reading
> > what the red, green and blue values are.  how would I do that?

> > TIA
> > flip

Other Threads