简体   繁体   English

Firemonkey(FMX)位图和颜色

[英]Firemonkey (FMX) bitmap and colours

Assume I have a small bitmap in Firemonkey (say 32x24 pixels). 假设我在Firemonkey中有一个小的位图(例如32x24像素)。 So I put a TImage onto a form and in the constructor there is this code: 因此,我将TImage放在表单上,​​并且在构造函数中有以下代码:

  Image1.Bitmap.Create(32, 24);
  if Image1.Bitmap.Canvas.BeginScene then
  try
    Image1.Bitmap.Canvas.Fill.Color := claBlack;
    Image1.Bitmap.Canvas.Stroke.Color := claYellow;
    Image1.Bitmap.Canvas.FillRect(RectF(0,0,32,24), 0, 0, AllCorners, $FF);
    Image1.Bitmap.Canvas.DrawLine(PointF(1,1), PointF(10,10), $FF);
  finally
    Image1.Bitmap.Canvas.EndScene;
    Image1.Bitmap.BitmapChanged;
  end;

This draws a nice diagonal line on blackground. 这在背景上绘制了一条漂亮的对角线。

What I want to do is now parse the bitmap to determine the pixels affected by the line draw. 我现在要做的是解析位图,以确定受线条影响的像素。 If I do a basic pixel by pixel check using: 如果我使用以下方法逐个像素进行基本检查:

  for y := 0 to 23 do
    for x := 0 to 31 do
      if Image1.Bitmap.Pixels[x,y] <> claBlack then
        memo1.Lines.Add(Format('x=%d. y=%d. c=%x', [x,y,Image1.Bitmap.Pixels[x,y]]));

the output onto my Memo is: 输出到我的备忘录中是:

x=0. y=0. c=FF3C3C00
x=1. y=0. c=FF3C3C00
x=0. y=1. c=FF3C3C00
x=1. y=1. c=FFE7E700
x=2. y=1. c=FF3C3C00
x=1. y=2. c=FF3C3C00
x=2. y=2. c=FFE7E700
x=3. y=2. c=FF3C3C00
x=2. y=3. c=FF3C3C00
x=3. y=3. c=FFE7E700
x=4. y=3. c=FF3C3C00
x=3. y=4. c=FF3C3C00
x=4. y=4. c=FFE7E700
x=5. y=4. c=FF3C3C00
x=4. y=5. c=FF3C3C00
x=5. y=5. c=FFE7E700
x=6. y=5. c=FF3C3C00
x=5. y=6. c=FF3C3C00
x=6. y=6. c=FFE7E700
x=7. y=6. c=FF3C3C00
x=6. y=7. c=FF3C3C00
x=7. y=7. c=FFE7E700
x=8. y=7. c=FF3C3C00
x=7. y=8. c=FF3C3C00
x=8. y=8. c=FFE7E700
x=9. y=8. c=FF3C3C00
x=8. y=9. c=FF3C3C00
x=9. y=9. c=FFE7E700
x=10. y=9. c=FF3C3C00
x=9. y=10. c=FF3C3C00
x=10. y=10. c=FF3C3C00

so it's interpreting and "blurring"? 所以它在解释和“模糊”? my line as the colours (represented by c above) are not equal to claYellow ($FFFF00). 我的行作为颜色(由上面的c表示)不等于claYellow($ FFFF00)。 If I draw a horizontal or vertical line, the effect is the same. 如果我画一条水平或垂直线,效果是一样的。 If I change my stroke thickness to 2 and draw a non-diagonal line it draws in claYellow but it covers 2 pixels. 如果我将笔触的粗细更改为2并绘制一条非对角线,它将绘制为claYellow,但它会覆盖2个像素。

So how can I determine the "true" pixels I've drawn on. 因此,如何确定绘制的“真实”像素。 In the above sample I would (could) look for $FFE7E700 but how do I know to look for that value (given that if I drew the line in a different colour, that value would be different). 在上面的示例中,我将(可能)寻找$ FFE7E700,但是我如何知道该值(假设如果我用其他颜色绘制线条,则该值将有所不同)。 I tried to see if there's a consistent "difference" between the colour I drew with and the actual colour rendered but couldn't locate one. 我试图查看我绘制的颜色与实际渲染的颜色之间是否存在一致的“差异”,但找不到该颜色。

Thanks 谢谢

FMX use antialiazing for drawing. FMX使用抗锯齿进行绘制。 If you would like draw line without blur effect you should use special function for pixel alignment: 如果您希望画线时没有模糊效果,则应使用特殊功能进行像素对齐:

  • TCanvas.AlignToPixel TCanvas.AlignToPixel
  • TCanvas.AlignToPixelVertically TCanvas.AlignToPixelVertically
  • TCanvas.AlignToPixelHorizontally TCanvas.AlignToPixelHorizo​​ntally

This functions automatically calculate pixel position for drawing without blur. 此功能自动计算绘图的像素位置而不会模糊。

Thank you 谢谢

The colors in the example are anti-aliased, meaning they're part the color you set, and part the background color. 示例中的颜色是抗锯齿的,这意味着它们既是您设置的颜色,又是背景颜色。 The precise ratio is based on many considerations done behind the scenes. 精确比率基于幕后进行的许多考虑。

Not familiar with FireMonkey(or delphi), so I can't tell you if there's a way around it, but if you want to know where a certain color lands what you could do is test the ratios between RGB values, that's assuming you draw only one line on a black background(otherwise, the ratios must be a range to catch pixels with large amounts of noise) 不熟悉FireMonkey(或delphi),因此我无法告诉您是否有解决方法,但是如果您想知道某种颜色在哪里着陆,您可以做的就是测试RGB值之间的比率,即假设您绘制了黑色背景上只有一行(否则,比率必须在一个范围内以捕获具有大量噪点的像素)

example: yellow(#ffff00) 示例:黄色(#ffff00)

red/green=1 红色/绿色= 1

red/blue=green/blue=#inf(or if you want, 255/1=255) 红色/蓝色=绿色/蓝色=#inf(或如果需要,255/1 = 255)

a sampled pixel could be #fcfc00 maintaining the ratios 采样像素可以是#fcfc00保持比率

a sampled pixel with noise could be #fcff09 has 具有噪声的采样像素可能是#fcff09具有

red/green=0.988 红色/绿色= 0.988

red/blue=28 红/蓝= 28

green/blue=28.33 绿色/蓝色= 28.33

red and green are still pretty close and both much higher than blue. 红色和绿色仍然非常接近,并且都比蓝色高得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM