Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 画布位置到图像像素_Wpf_Image_Canvas_Pixel - Fatal编程技术网

Wpf 画布位置到图像像素

Wpf 画布位置到图像像素,wpf,image,canvas,pixel,Wpf,Image,Canvas,Pixel,我想在图像上绘制矩形来标记特定区域。 我看到了这个问题:它奏效了。我在图像上画了一个矩形。现在我想得到图像上真正的像素位置。我知道我在画布上得到了一些数据。左边,画布。顶部。但是画布和图像位置之间的关系在哪里呢 感谢Lyror让这项功能发挥作用,您可以轻松地将其放入如下视图框中: <Viewbox> <!-- I will make this construct fit everywhere --> <Grid> <!-- I will be e

我想在图像上绘制矩形来标记特定区域。 我看到了这个问题:它奏效了。我在图像上画了一个矩形。现在我想得到图像上真正的像素位置。我知道我在画布上得到了一些数据。左边,画布。顶部。但是画布和图像位置之间的关系在哪里呢


感谢Lyror

让这项功能发挥作用,您可以轻松地将其放入如下视图框中:

<Viewbox> <!-- I will make this construct fit everywhere -->
    <Grid> <!-- I will be exactly the size of the image -->

        <Image Source="/MyImagegeWithResolutionOf1080x720p.jpg"
            Width="{Binding Source.PixelWidth, RelativeSource={RelativeSource Self}}"
            Height="{Binding Source.PixelHeight, RelativeSource={RelativeSource Self}}"
            Stretch="Fill"/>

        <Canvas> <!-- use me to draw your stuff -->
            <Rectangle Width="10" Height="10" Canvas.Bottom="360" Canvas.Left="540"/> <!-- I will be in the center -->
         </Canvas>
    </Grid>
</Viewbox>

你可以在图像上画图,更好的说法是实际操作位图来实现这一点。只有当图像的DPI为96时,这将为你提供实际的像素位置。他没有问更具体的问题,我认为这很可能满足他的需要。请随时改进我的回答,或者很可能不会,没有人知道。我投票把这个问题作为离题题来结束,因为它缺少一个精确的问题描述。我不同意,但我想这可能发生在互联网的宽度上。。。对我来说,尤其是他提供的链接清楚地表明了他想做什么,他并没有开始担心WPF中的像素到底是什么。问题是图像上的真实像素位置,这让我认为OP很清楚这一点。如果他们从图片库中加载图像以剪切作物或其他东西,您的方法将无法处理没有96 DPI的图像。我的图片库中几乎所有的图像都没有96 DPI。只是说说而已。