locked
using List<System.Drawing.Image> collection in Window 8 app

    Question

  • I have a .NET/C# library that does some images processing and after that it returns List collection. I am now creating a Windows 8 application using JavaScript/HTML that will be displaying those images. My question is can I use List directly or do I have to perform any type of marshaling before this type could be used?
    Wednesday, February 19, 2014 8:26 PM

Answers

  • How much rewriting will depend on the library. If most of the code is app logic then that will likely port easily, but any dependencies on unavailable parts of the .Net Framework (such as System.Drawing) will need to be removed. How to remove them and what to replace them with will depend on what exactly the library is doing.

    You'll run into similar issues trying to use this library in contexts such as an ASP.Net app, where System.Drawing is not supported (although it is not actively blocked, it is not supported and won't always work right in non-interactive environments. Finagle's Law applies).

    --Rob

    • Marked as answer by Kam2011 Thursday, February 20, 2014 4:12 PM
    Thursday, February 20, 2014 4:32 AM
    Moderator

All replies

  • You can wrap a .Net library in a Windows Runtime Component and call it from a JavaScript app, but the library has to be valid for the .Net Framework for Windows Store.

    System.Drawing is not available to Windows Store apps, so the library you have won't be usable in your Windows Store app.

    See .NET for Windows Store apps and Walkthrough: Creating a simple component in C# or Visual Basic and calling it from JavaScript

    --Rob

    Wednesday, February 19, 2014 8:30 PM
    Moderator
  • Thanks Rob. Is there any sample of how to wrap a .net library in Windows Runtime Component? The walkthough link you provide seem to show creating a Windows Runtime component from scatch and call from JavaScript but I guess what I am looking for is something that can marshall from System.Drawing.Image to Windows.UI.Xaml.Media equivalent in WinJS? Anything related to this scenario will be extremely helpful
    Wednesday, February 19, 2014 8:37 PM
  • There isn't a general mapping between System.Drawing and Windows.UI.Xaml.Media. They are conceptually fairly different. Using Windows.UI.Xaml is also not going to work in a JavaScript app since they both rely on owning the rendering. You will likely be better off rewriting the component to do the image processing in DirectX.

    --Rob

    Wednesday, February 19, 2014 8:45 PM
    Moderator
  • This library is result of years of work by many team members that have gone through rigorous testing etc. I cannot believe the solution will be to re-write whole thing. The company has invested so much building this library using .NET technologies. I can understand if it requires just to write a wrapper for data type marshaling but writing whole again is just not going to fly. Do you see any management getting convinced to spent that amount of work again just to get an app on Windows Store :)

    • Edited by Kam2011 Wednesday, February 19, 2014 9:03 PM
    Wednesday, February 19, 2014 9:01 PM
  • How much rewriting will depend on the library. If most of the code is app logic then that will likely port easily, but any dependencies on unavailable parts of the .Net Framework (such as System.Drawing) will need to be removed. How to remove them and what to replace them with will depend on what exactly the library is doing.

    You'll run into similar issues trying to use this library in contexts such as an ASP.Net app, where System.Drawing is not supported (although it is not actively blocked, it is not supported and won't always work right in non-interactive environments. Finagle's Law applies).

    --Rob

    • Marked as answer by Kam2011 Thursday, February 20, 2014 4:12 PM
    Thursday, February 20, 2014 4:32 AM
    Moderator
  • Thanks Rob for your help.
    Thursday, February 20, 2014 3:42 PM