Reputation: 283
I'm currently in the process of porting an existing C# project from the .Net Framework 4.5 to Portable Class Library profile 111. I need to save and load image data to / from a stream using the PNG format.
As you probably know, the System.Drawing
namespace is not available in this profile, so there is no way I can use the Bitmap
class for this, as I did previously. So far, my web research did not yield any "obvious solutions" for image compression in C# when System.Drawing
is unavailable.
In answering this question, please assume that providing different platform-versions of my library with a mere PCL "frontend" is not an option in this case.
How to approach this?
Upvotes: 1
Views: 1022
Reputation: 5594
The Portable Class Library does not support any image or UI elements by design, so your problem will likely be quite difficult to solve without extracting some functionality into a minimal platform-dependent library. From doing some searching online, it seems like other devs presented with your same problem have resorted to offloading the image work to either a web service or a platform-dependent library.
Of course you could always just deal with byte[]
and roll your own PNG encoder/decoder. Yay. Be aware there are various flavors available based on different "filters", etc.
The PCL link here states that the assemblies available within a Portable Class Library project are:
mscorlib.dll
System.dll
System.Core.dll
System.Xml.dll
System.ComponentModel.Composition.dll
System.Net.dll
System.Runtime.Serialization.dll
System.ServiceModel.dll
System.Xml.Serialization.dll
System.Windows.dll (from Silverlight)
That last assembly is the only one I am aware of that has any image-related functionality. It contains the System.Windows.Controls.Image
class which supports the display of an image in the JPEG or PNG file formats. The caveat, of course, (based on the matrix contained in the aforementioned link), is that this System.Windows.dll
Silverlight assembly is only available in PCL when targeting the Silverlight platform and/or the Windows Phone 7 platform. It will not be available to the more general .NET Framework 4 platform, nor the Xbox 360 platform.
If you did end up being forced to go with a minimal platform-dependent library, the WPF framework does have the System.Windows.Media.Imaging
namespace with comprehensive image format encoding/decoding support (including PNG format).
Upvotes: 1