如何暗示wpf线颜色还原与其混合背景 [英] How to imply wpf line color revert with its mixture backgroud

查看:55
本文介绍了如何暗示wpf线颜色还原与其混合背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在灰色图像上方画一条线。

I want to draw a line above an image which is gray colored.

我想设置线条颜色还原为背景像素。

and I want to set the line color revert with its background in pixel.

如果该行由10000像素组成,并且每个像素颜色将取决于图像背景像素的颜色。

If the line is consists of 10000 pixels, and each pixel color will depend on the color of its background pixel of the image.

到现在为止,我不知道不知道如何实现它,任何人都可以给出一些建议吗?

By now, I don't know how to implement it, Can anyone give some suggestions?

非常感谢!

推荐答案

您好    Likevin33,



>>如何暗示wpf线条颜色还原其混合物背景



和我想设置线条颜色还原及其背景像素。



如果该行由10000个像素组成,并且每个像素颜色将取决于其背景像素的颜色。



到现在为止,我不知道如何实现它,任何人都可以给出一些建议?



您可以使用MouseDown或MouseUp或MouseMove 用于捕获像素在鼠标指针下方的颜色的事件。

Hi   Likevin33,

>>How to imply wpf line color revert with its mixture backgroud

and I want to set the line color revert with its background in pixel.

If the line is consists of 10000 pixels, and each pixel color will depend on the color of its background pixel of the image.

By now, I don't know how to implement it, Can anyone give some suggestions?

You can use the MouseDown or MouseUp or MouseMove  event to capture what color the pixel is immeidately under the mouse pointer.

您可以参考以下代码并将其放在您的身边。使用SelectedColor绘制一条线。



您可以保存集合中的所有点和颜色,然后在控件上绘制线条。这是一个想法,你需要实现自己的细节。

You can refer the following code and put it on your side. Use the SelectedColor to draw a line.

You can save all points and colors in a collection, then draw the line on a control. This is an idea, you need to implement your own details.

       Point position = Mouse.GetPosition(your element imageaa);
            End = new Point(position.X, position.Y);

            // Use RenderTargetBitmap to get the visual, in case the image has been transformed.
            var renderTargetBitmap = new RenderTargetBitmap((int)imageaa.ActualWidth,
                                                            (int)imageaa.ActualHeight,
                                                            96, 96, PixelFormats.Default);
            renderTargetBitmap.Render(imageaa);

            // Make sure that the point is within the dimensions of the image.
            if ((position.X <= renderTargetBitmap.PixelWidth) && (position.Y <= renderTargetBitmap.PixelHeight))
            {
                // Create a cropped image at the supplied point coordinates.
                var croppedBitmap = new CroppedBitmap(renderTargetBitmap,
                                                      new Int32Rect((int)position.X, (int)position.Y, 1, 1));

                // Copy the sampled pixel to a byte array.
                var pixels = new byte[4];
                croppedBitmap.CopyPixels(pixels, 4, 0);

                // Assign the sampled color to a SolidColorBrush and return as conversion.
                Color SelectedColor = Color.FromArgb(255, pixels[2], pixels[1], pixels[0]);
            }




WPF中的形状和基本绘图概述:




最好的问候,

$
Yong Lu


Shapes and Basic Drawing in WPF Overview:


Best Regards,

Yong Lu


这篇关于如何暗示wpf线颜色还原与其混合背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆