WPF 获取图像像素的屏幕坐标(不要鼠标点击获得,而是知道哪个像素点得到对应的数据

WPF 获取图像像素的屏幕坐标(不要鼠标点击获得,而是知道哪个像素点得到对应的数据,第1张

1、新建一个 Window,添加一个Grid

<Window x:Class="WpfApplication1MainWindow"
        xmlns=";

2、添加类 FunnyBrush,这是我自己写着玩的

public class FunnyBrush
{
    public static void Draw(Panel panel)
    {
        var brush = new RadialGradientBrush();
        var center = new Point(panelActualWidth / 2d, panelActualHeight / 2d);
        brushCenter = center;
        brushGradientOrigin = center;
        brushRadiusX = centerX;
        brushRadiusY = centerY;
        brushMappingMode = BrushMappingModeAbsolute;
        ConsoleWriteLine(center);
        var stops = new GradientStopCollection();
        stopsAdd(new GradientStop(ColorsYellow, 0d));
        stopsAdd(new GradientStop(ColorsRed, 025d));
        stopsAdd(new GradientStop(ColorsBlue, 075d));
        stopsAdd(new GradientStop(ColorsLimeGreen, 1d));
        brushGradientStops = stops;
        panelBackground = brush;
        var win = FindParent<Window>(panel) as FrameworkElement;
        if (win == null) win = panel;
        winMouseMove += (obj, args) =>
        {
            brushGradientOrigin = argsGetPosition(panel);
        };
        winSizeChanged += (obj, args) =>
        {
            var pt = new Point(panelActualWidth / 2d, panelActualHeight / 2d);
            brushCenter = pt;
            brushRadiusX = ptX;
            brushRadiusY = ptY;
        };
    }
    // 这个方法来自
    // >}

3、在 Window_Loaded 事件中添加代码

FunnyBrushDraw(panel);

假设原为“imagejpg”

代码如下:

clc;

clear;

%读入原图像

image = imread('imagejpg');

s = size(image);

%s=[98,97,3],表示image是3个9897的矩阵,分别代表这个图像每个像素点的R、G、B值

%点[30,30]处的RGB数值:

p_r = image(30,30,1);

p_g = image(30,30,2);

p_b = image(30,30,3);

%分别读取RGB

image_r = image(:,:,1);

image_g = image(:,:,2);

image_b = image(:,:,3);

%测试RGB输出

subplot(2,2,1),imshow(image_r),title('Red component');  

subplot(2,2,2),imshow(image_g),title('green component');  

subplot(2,2,3),imshow(image_g),title('blue component');  

subplot(2,2,4),imshow(image),title('original image');

扩展资料:

1、文件的数据,简单地说,就是一个二维数组,二维数组的行对应图像的高,二维数组的列对应图像的宽,二维数组的元素对应图像的像素,二维数组元素的值就是像素的灰度值。

2、彩色空间是用来表示彩色的数学模型,又被称为彩色模型。RGB色彩模式是工业界的一种颜色标准,是通过对红(R)、绿(G)、蓝(B)三个颜色通道的变化以及它们相互之间的叠加来得到各式各样的颜色的。

参考资料:

百度百科-imread

GetPixel函数可以得到指定坐标点的像素值。

函数功能:该函数检索指定坐标点的像素的RGB颜色值。
函数原型:COLORREF GetPixel(HDC hdc, int nXPos, int nYPos)
参数

hdc:设备环境句柄。
nXPos:指定要检查的像素点的逻辑X轴坐标。
nYPos:指定要检查的像素点的逻辑Y轴坐标。
返回值:返回值是该象像点的RGB值。如果指定的像素点在当前剪辑区之外;那么返回值是CLR_INVALID。

GetCursorPos函数可以得到当前鼠标的坐标点。

函数功能:该函数检取光标的位置,以屏幕坐标表示。
函数原型:BOOL GetCursorPos(LPPOINT lpPoint)。
参数

IpPoint:POINT结构指针,该结构接收光标的屏幕坐标。

通常一幅图像有四个焦角点,已知图像的大小为widthheight,那么四个角点的坐标分别为:(0,0), (0,width-1), (height-1,0), (width-1,height-1)。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13383109.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-25
下一篇 2023-07-25

发表评论

登录后才能评论

评论列表(0条)

保存