Reputation: 652
Recently I wrote a WPF program for detecting faces in the pictures. This program uses one of the ProjectOxford's APIs that is known as FaceAPI. Then I got an idea to port my application from WPF to UWP (Universal Windows Platform). But, during the development I faced up the problem with System.Windows.Media namespace. In my UWP application I just do not have such namespace, consequently I can not get access to all included classes, such that DrawingVisual, DrawingContext etc.
Here is problematic code block from WPF which need to be ported to 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;
}
Any ideas how to replace that?
Upvotes: 3
Views: 2498
Reputation: 921
UWP uses a new set of namespaces -- the majority of these prefixed with Windows.* which is in contrast to the System.* prefix for WPF, although there are System.* namespaces used both by UWP and WPF. Here is a link for the new namespaces. You may also like to read the Guide to Universal Windows Platform apps for a better grasp of UWP basics.
As shown in the comment section, what you need is a namespace that starts with Windows.* and the links provided should put you right.
Upvotes: 2