비슷하게 어떻게 변환하에서 마우스 좌표하는 픽셀의 좌표를 TransformedBitmap? 그러나 추가 주름 나 Image
실제로에 포함되는 더 큰 부모로 Grid
는 배경,그리고 나는 픽셀 좌표하는 또한 정확한 유혹 할 때 지역에서의 경계를 넘어 이미지입니다.
여기에 내 XAML:
<DockPanel>
<Label DockPanel.Dock="Bottom" Name="TheLabel" />
<Grid DockPanel.Dock="Top" Name="TheGrid" Background="Gray" MouseMove="TheGrid_MouseMove">
<Image Name="TheImage" Stretch="Uniform" RenderOptions.BitmapScalingMode="NearestNeighbor" />
</Grid>
</DockPanel>
그는 코드는 다음과 같습니다:
public MainWindow()
{
InitializeComponent();
const int WIDTH = 4;
const int HEIGHT = 3;
byte[] pixels = new byte[WIDTH * HEIGHT * 3];
// top-left corner red, bottom-right corner blue for orientation
pixels[0] = Colors.Red.B;
pixels[1] = Colors.Red.G;
pixels[2] = Colors.Red.R;
pixels[(WIDTH * (HEIGHT - 1) + (WIDTH - 1)) * 3 + 0] = Colors.Blue.B;
pixels[(WIDTH * (HEIGHT - 1) + (WIDTH - 1)) * 3 + 1] = Colors.Blue.G;
pixels[(WIDTH * (HEIGHT - 1) + (WIDTH - 1)) * 3 + 2] = Colors.Blue.R;
BitmapSource bs = BitmapSource.Create(WIDTH, HEIGHT, 96.0, 96.0, PixelFormats.Bgr24, null, pixels, WIDTH * 3);
TheImage.Source = new TransformedBitmap(bs, new RotateTransform(90.0));
}
private void TheGrid_MouseMove(object sender, MouseEventArgs e)
{
Point p = TheGrid.TranslatePoint(e.GetPosition(TheGrid), TheImage);
if (TheImage.Source is BitmapSource bs)
{
p = new Point(p.X * bs.PixelWidth / TheImage.ActualWidth, p.Y * bs.PixelHeight / TheImage.ActualHeight);
if (TheImage.Source is TransformedBitmap tb)
{
Matrix inverse = tb.Transform.Value;
inverse.Invert();
inverse.OffsetX = 0.0;
inverse.OffsetY = 0.0;
p = inverse.Transform(p);
int w = tb.Source.PixelWidth;
int h = tb.Source.PixelHeight;
p = new Point((p.X + w) % w, (p.Y + h) % h);
}
TheLabel.Content = p.ToString();
}
}
대부분이 잘 작동하지만,경우에는 그레이의 왼쪽에 있는 회전 이미지(대략 X 에서는 아래 스크린샷),당신은 당신을 얻을 y-coordinate(0.5)만드는 것처럼 보이는 이미지 때에 현실을 외부와의 y 좌표보다 높아야 합 이미지 높이를 반영합니다.
이것은 중요한 내용을 선택하려면 투자수익률을 기대할 수 있으며,나를 알아야 할 때는 선택을 넘어 이미지의 범위,그래도 나는 여전히고 싶어 그것을 할 수 있습니다.