1

I have a project which targets the .NET Standard 2.0. This project does only contain resources such as icons, images, strings,.. If I import a .png within a resource file (.resx) and set the code gen. to public, it generates those fields as byte[] rather than System.Drawing.Bitmap (which I would need). All images are marked as embedded resources, where is the problem? Using .NET Framework 4.8 it worked just fine. Using Visual Studio 2019.

E.g:

        public static byte[] accept {
        get {
            object obj = ResourceManager.GetObject("accept", resourceCulture);
            return ((byte[])(obj));
        }
    }
Florent
  • 355
  • 2
  • 12
  • Where's is the problem? It's the calling code that needs the Bitmap, not the Library. You can just have `Image img = new ImageConverter().ConvertFrom(accept()) as Image;`. Now you can use your .Net Standard Library with both .Net Framework and .Net Core. -- Even if you could, what would you target in a Library? `System.Drawing.dll` or `System.Drawing.Common.dll` (or `PresentationCore.dll`)? This is Windows specific implementation that .Net standard doesn't care about. – Jimi Aug 22 '21 at 11:11
  • In .NET Standard 2.0 you need a NuGet [package](https://www.nuget.org/packages/System.Drawing.Common) to support `Bitmap` and other GDI+ types, maybe that's why it is generated as a `byte[]` by default. And though `ImageConverter` supports `byte[]` it is also unavailable in .NET Standard 2.0 so I would just simply use the `Stream` constructor: `new Bitmap(new MemoryStream(Resources.accept))` – György Kőszeg Aug 22 '21 at 11:18
  • @GyörgyKőszeg *It's the calling code that needs the Bitmap, not the Library*. You use ImageConverter in the code that needs a Bitmap. Or similar to get a BitmapSource. -- Whatever this Library is for. Not clear why you would add bitmaps to a .Net Standard Library instead of using a satellite assembly to store that kind of resources. – Jimi Aug 22 '21 at 11:28
  • @Jimi: _"Not clear why you would add bitmaps to a .Net Standard Library"_ - read my comment carefully: in my example the library resource still has the `byte[]`. The `Bitmap` instantiation itself can be in a consumer application (if it happens to be a WinForms app). But storing just a `byte[]` (or a `MemoryStream`) makes possible to use .resx image resources even from a [WPF app](https://stackoverflow.com/a/57099811/5114784). – György Kőszeg Aug 22 '21 at 11:47
  • @GyörgyKőszeg Yes, well, that's what I said in the first place. The point is, this is not the role of a .Net Standard (agnostic) Library; also, the OP is probably using Language dependent resources, which are usually stored in Language dependent assemblies, not a .Net Standard Library. These kind of assemblies are commonly used so you can switch UI Language just setting a couple of values, both at startup and while the app is running. – Jimi Aug 22 '21 at 11:53

0 Answers0