Firemonkey(FMX)位图和颜色 [英] Firemonkey (FMX) bitmap and colours
问题描述
Image1.Bitmap.Create(32,24 );
如果Image1.Bitmap.Canvas.BeginScene然后
尝试
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;
结束
这是在黑地上画一条很好的对角线。
我现在要做的是解析位图,以确定受线条影响的像素。如果我使用以下方式进行基本的逐像素检查:
for y:= 0 to 23 do
for x: = 0到31 do
如果Image1.Bitmap.Pixels [x,y] claBlack然后
memo1.Lines.Add(Format('x =%d。y =%d。c =%x',[x,y,Image1.Bitmap.Pixels [x,y]])
我的备忘录上的输出是:
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
所以它的解释和模糊?我的行作为颜色(由上面的c表示)不等于claYellow($ FFFF00)。如果我画一条水平或垂直线,效果是一样的。如果我将笔画厚度更改为2,并绘制非对角线,则绘制在claYellow中,但它覆盖了2个像素。
那么如何确定true像素我画了在上面的示例中,我可以(可以)寻找$ FFE7E700,但是如何知道这个值(如果我用不同的颜色绘制线,那个值会有所不同)。我试图看看我绘制的颜色与渲染的实际颜色之间是否存在一致的差异。
感谢
FMX使用antialiazizing进行绘图。如果你想画画线没有模糊效果,你应该使用特殊的像素对齐功能:
- TCanvas.AlignToPixel
- TCanvas.AlignToPixelVertically
- TCanvas.AlignToPixelHorizontally
此功能自动计算图形的像素位置,而不会出现模糊。
谢谢
Assume I have a small bitmap in Firemonkey (say 32x24 pixels). So I put a TImage onto a form and in the constructor there is this code:
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). 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.
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). 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. If you would like draw line without blur effect you should use special function for pixel alignment:
- TCanvas.AlignToPixel
- TCanvas.AlignToPixelVertically
- TCanvas.AlignToPixelHorizontally
This functions automatically calculate pixel position for drawing without blur.
Thank you
这篇关于Firemonkey(FMX)位图和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!