创建图像和彩色红外? [英] Create an image and colored ir?
问题描述
如何创建图像以及如何使用十六进制颜色像素对像素进行着色?
例如。我想创建一个100x100像素的图像,我想要1x1区域的颜色为'$ 002125',2x2区域的颜色为'$ 125487'...。我该怎么做? >谢谢您的回答。
为您提供了一个简单的示例。使用Canvas.Pixels而不是Scanline。尽管Scanline速度更快,但我认为它非常适合。颜色是随机生成的,因此您只需要替换代码的这一部分即可。
过程TForm1.GenerateImageWithRandomColors;
var
位图:TBitmap;
I,J:整数;
ColorHEX:字符串;
开始
位图:= TBitmap.Create;
随机化;
试试
Bitmap.PixelFormat:= pf24bit;
Bitmap.Width:= 100;
Bitmap.Height:= 100;
I的
:= 0到Pred(Bitmap.Width)做
开始
J的=:0到Pred(Bitmap.Height)做
开始
Bitmap.Canvas.Pixels [I,J]:= RGB(Random(256),
Random(256),
Random(256));
//获取颜色的十六进制值并对其进行处理
ColorHEX:= ColorToHex(Bitmap.Canvas.Pixels [I,J]);
结尾;
结尾;
Bitmap.SaveToFile(’test.bmp’);
最后
位图。
结尾;
结尾;
函数TForm1.ColorToHex(Color:TColor):字符串;
开始
结果:=
IntToHex(GetRValue(Color),2)+
IntToHex(GetGValue(Color),2)+
IntToHex(GetBValue(Color) ,2);
结尾;
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..
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;
这篇关于创建图像和彩色红外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!