System.Windows.Media 在 UWP 中
System.Windows.Media in UWP
最近写了一个WPF程序,用于检测图片中的人脸。该程序使用 ProjectOxford 的 API 之一,称为 FaceAPI。
然后我想到将我的应用程序从 WPF 移植到 UWP(通用 Windows 平台)。但是,在开发过程中,我遇到了 System.Windows.Media 命名空间的问题。在我的 UWP 应用程序中,我只是没有这样的命名空间,因此我无法访问所有包含的内容 类,例如 DrawingVisual、DrawingContext 等
这是 WPF 中有问题的代码块,需要移植到 UWP:
if (faceRects.Length > 0)
{
DrawingVisual visual = new DrawingVisual();
DrawingContext drawindContext = visual.RenderOpen();
drawindContext.drawimage(bitmapImage,
new Rect(0, 0, bitmapImage.Width, bitmapImage.Height));
double dpi = bitmapImage.DpiX;
double resizefactor = 96 / dpi;
foreach (var facerect in faceRects)
{
drawindContext.drawrectangle(
Brushes.transparent,
new Pen(Brushes.red, 2),
new Rect(
faceRect.Left * resizefactor,
faceRect.Top * resizefactor,
faceRect.Width * resizefactor,
faceRect.Height * resizefactor
)
);
}
drawindcontext.close();
rendertargetbitmap facewithrectbitmap = new rendertargetbitmap(
(int)(bitmapsource.pixelwidth * resizefactor),
(int)(bitmapsource.pixelheight * resizefactor),
96,
96,
pixelformats.pbgra32);
facewithrectbitmap.render(visual);
facephoto.source = facewithrectbitmap;
}
知道如何替换它吗?
UWP 使用了一组新的命名空间——其中大部分以 Windows.* 为前缀,这与 WPF 的 System.* 前缀形成对比,尽管 System.* 命名空间同时被使用UWP 和 WPF。这里有一个 link for the new namespaces. You may also like to read the Guide to Universal Windows Platform apps 可以更好地掌握 UWP 基础知识。
如评论部分所示,您需要的是以 Windows.* 开头的命名空间,提供的链接应该正确无误。
最近写了一个WPF程序,用于检测图片中的人脸。该程序使用 ProjectOxford 的 API 之一,称为 FaceAPI。 然后我想到将我的应用程序从 WPF 移植到 UWP(通用 Windows 平台)。但是,在开发过程中,我遇到了 System.Windows.Media 命名空间的问题。在我的 UWP 应用程序中,我只是没有这样的命名空间,因此我无法访问所有包含的内容 类,例如 DrawingVisual、DrawingContext 等
这是 WPF 中有问题的代码块,需要移植到 UWP:
if (faceRects.Length > 0)
{
DrawingVisual visual = new DrawingVisual();
DrawingContext drawindContext = visual.RenderOpen();
drawindContext.drawimage(bitmapImage,
new Rect(0, 0, bitmapImage.Width, bitmapImage.Height));
double dpi = bitmapImage.DpiX;
double resizefactor = 96 / dpi;
foreach (var facerect in faceRects)
{
drawindContext.drawrectangle(
Brushes.transparent,
new Pen(Brushes.red, 2),
new Rect(
faceRect.Left * resizefactor,
faceRect.Top * resizefactor,
faceRect.Width * resizefactor,
faceRect.Height * resizefactor
)
);
}
drawindcontext.close();
rendertargetbitmap facewithrectbitmap = new rendertargetbitmap(
(int)(bitmapsource.pixelwidth * resizefactor),
(int)(bitmapsource.pixelheight * resizefactor),
96,
96,
pixelformats.pbgra32);
facewithrectbitmap.render(visual);
facephoto.source = facewithrectbitmap;
}
知道如何替换它吗?
UWP 使用了一组新的命名空间——其中大部分以 Windows.* 为前缀,这与 WPF 的 System.* 前缀形成对比,尽管 System.* 命名空间同时被使用UWP 和 WPF。这里有一个 link for the new namespaces. You may also like to read the Guide to Universal Windows Platform apps 可以更好地掌握 UWP 基础知识。
如评论部分所示,您需要的是以 Windows.* 开头的命名空间,提供的链接应该正确无误。