• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 
21 November 2024, 23:31:25

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - binfch

1
Thank you, works perfectly!
2
Hi there

I have a small test procedure to count how many times a color does occure within an image -> However it does not work, I think the issue is around FindColor() that I don't use correctly. Any idea where the mistake is?

Code (pascal) Select
procedure TForm1.Button1Click(Sender: TObject);
var
  NumberOfColors: Integer;
  ImageData: TImageData;
  ImagingBitmap: TImagingBitmap;
  Counter: Integer;
  Palette: PPalette32;
  ColorRecord: TColor32Rec;
  ColorArray: Array of Integer;
  Row, Col: Integer;
begin
  NumberOfColors := 16;
  SetLength(ColorArray, NumberOfColors);

  ImagingBitmap := TImagingBitmap.Create;
  InitImage(ImageData);

  for Counter := 0 to NumberOfColors -1 do
    ColorArray[Counter] := 0;

  try
    LoadImageFromFile('car1.png', ImageData);
    ReduceColors(ImageData, NumberOfColors);
    Palette := @ImageData.Palette;

    //List all the colors
    for Counter := 0 to NumberOfColors -1 do
      Memo1.Lines.Add( IntToStr(Counter) + ':(' + IntToStr(Palette[Counter].R) + ',' +
                                                  IntToStr(Palette[Counter].G) + ',' +
                                                  IntToStr(Palette[Counter].B) + ')' );

    //Count how many times a color is used
    for Row := 0 to ImageData.Height -1 do begin
      for Col := 0 to ImageData.Width -1 do begin
        ColorRecord := GetPixel32(ImageData, Col, Row);
        Counter := FindColor(Palette, NumberOfColors, ColorRecord.Color);
        Inc(ColorArray[Counter]);
      end;
    end;

    //List the counting result
    for Counter := 0 to NumberOfColors -1 do
      Memo2.Lines.Add( IntToStr(Counter) + ':' + IntToStr(ColorArray[Counter]) );

    //Draw the image on the canvas
    ImagingBitmap.AssignFromImageData(ImageData);
    Form1.Canvas.Draw(0, 0, ImagingBitmap);
  finally
    FreeImage(ImageData);
    ImagingBitmap.Free;
  end;
end;


Thanks in advance,
P.
SMF spam blocked by CleanTalk