-1

如何在此处使用此功能:创建图像和彩色红外?对于JPEG?

因为Bmp格式的尺寸很大。我想用小尺寸的图片来学习。

4

1 回答 1

6
procedure TForm1.GenerateImageWithRandomColors;
var
  I, J: Integer;
  ColorHEX: string;
  Bitmap: TBitmap;
  JpegImg: TJpegImage;
begin
  Randomize;

  Bitmap := TBitmap.Create;
  try        
    Bitmap.Width := 100;
    Bitmap.Height := 100;
    Bitmap.PixelFormat := pf24bit;

    for I := 0 to Pred(Bitmap.Width) do
    begin
      for J := 0 to Pred(Bitmap.Height) do
      begin
        Bitmap.Canvas.Pixels[I, J] := RGB(Random(256),
           Random(256),
           Random(256));

        // get the HEX value of color and do something with it
        ColorHEX := ColorToHex(Bitmap.Canvas.Pixels[I, J]);
      end;
    end;

    JpegImg := TJpegImage.Create;
    try
      JpegImg.Assign(Bitmap);
      JpegImg.SaveToFile('test.jpg');
    finally
      JpegImg.Free;
    end;

  finally
    Bitmap.Free;
  end;
end;

function TForm1.ColorToHex(Color : TColor): string;
begin
  Result :=
    IntToHex(GetRValue(Color), 2) +
    IntToHex(GetGValue(Color), 2) +
    IntToHex(GetBValue(Color), 2);
end;
于 2012-08-01T19:59:40.287 回答