Image shows as black square after saving to a file.
I have a signature block tool in an Android App. This image is converted to a byte[] and saved to an SQL database.
I am pretty sure the byte[] conversion is working as when I in c# take the byte array and convert it to a bitmap, it shows correctly in an image control. However, if I take the bitmap and save it as a file, in some programs it displays correctly, i.e. Paint, or paint.net etc. But if I use an "photo" type app, the image is just black. I have also tried to insert the image into a printed report, and again it just shows as a black rectangle.
Below is my code, I would be grateful for any advice of what I am doing wrong.
This is the code I use to convert the image to a byte array for storing.
private static byte[] MakeBytes(Bitmap bitmap) { using (var stream = new MemoryStream()) { bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream); var bitmapData = stream.ToArray(); return bitmapData; } }
Then finally this is the code I use to save the image as a graphics file, to insert into a report.
if (invoice.Signature != null)using (var ms = new MemoryStream(invoice.Signature)){ var image = (Bitmap)Image.FromStream(ms); image.Save(tempFileName);}