You can try to use the following code:
public static async Task<byte[]> ImageSourceToByteArrayAsync(){ var assem = Assembly.GetExecutingAssembly(); using var stream = assem.GetManifestResourceStream("ProjectName.Resources.Images.test.png"); byte[] bytesAvailable = new byte[stream.Length]; stream.Read(bytesAvailable, 0, bytesAvailable.Length); return bytesAvailable;}
The test.png
is in the \Resources\Images
and its build action is EmbeddedResource.