0

I have a WPF app. My main project references another project (My.Tools.Images) within the solution. My.Tools.Images project contains some images.

Then from main project I am trying to read all bytes from SampleImage.png file located in that referenced project 'My.Tools.Images' by creating an Uri and later in some way, convert it into a byte array:

Uri myUri = new Uri("/My.Tools.Images;component/Files/SampleImage.png", UriKind.Relative);

... but once created the Uri I do not know how to read all bytes from there, I mean, convert SampleImage.png into a byte array.

How can I do this?

Note: I want to avoid to keep a link with the SampleImage.png opened from disk because later I need to delete this file from another place, so if this file is in use (opened), I cannot delete it.

Willy
  • 9,848
  • 22
  • 141
  • 284
  • 1
    As a note, that URI looks odd. If it is supposed to reference an assembly resource file, it should be `new Uri("pack://application:,,,/My.Tools.Images;component/Files/SampleImage.png")` – Clemens Feb 13 '19 at 20:49
  • @Clemens Thanks again man! Also, I have found an answer you did for a similar case here: https://stackoverflow.com/questions/14929760/convert-resource-to-byte This work great for Uris created from a file path like "C:\temp", network places like "\\myServer\path" or packed resources like ""pack://application:,,,/My.Tools.Images;component/Files/SampleImage.png". The only thing is that you need to provide which type of encoder to use depending on the image format you are working with (png, jpeg, tiff, bmp, gif or wmp) ... – Willy Feb 14 '19 at 01:58
  • @Clemens ...It would be good if in that conversion function "GetImageBuffer" no dependency would be made with the image format you are currently working on. Anyway are applied the solution you proposed there and it works. – Willy Feb 14 '19 at 01:58

0 Answers0