Create an image and colored ir?

冷暖自知 提交于 2019-12-23 04:03:39

问题


how can I create an image and how can I colored it pixel by pixel using hexadecimal code of colors?

For ex. I wanna create a 100x100 pixel image and I wanto to 1x1 area's color is '$002125',2x2 area's color is '$125487'.... How can I do it?

Thank you for your answers..


回答1:


Made a simple sample for you. Using Canvas.Pixels not Scanline. Scanline is faster though but for start I think it suits just fine. The colors are randomly generated, so you just need to replace this part of the code.

    procedure TForm1.GenerateImageWithRandomColors;
    var
      Bitmap: TBitmap;
      I, J: Integer;
      ColorHEX: string;

    begin
      Bitmap := TBitmap.Create;
      Randomize;

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

        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;

        Bitmap.SaveToFile('test.bmp');
      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;


来源:https://stackoverflow.com/questions/11728198/create-an-image-and-colored-ir

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!