-1

I am creating an EmguCv Image object then retrieving it bytes and trying to create a Bitmap. This is my code

Image<Bgr, byte> myImg = new Image<Bgr, byte>("C:filePathToPng");
byte[] mybytes = myImg.Bytes; //This does NOT work
// byte[] m1bytes = File.ReadAllBytes(@"C:filePathToPng.png");    This does work
using (var stream = new MemoryStream(mybytes))
using (var bitmap = new Bitmap(stream)) //PARAMETER IS NOT VALID HERE
{
....

However I am getting an error that is in the description.

Any suggestions on how to fix this would be great

Community
  • 1
  • 1
RyeGuy
  • 4,213
  • 10
  • 33
  • 57
  • 1
    Maybe the error happens when converting the Bitmap to the base64 string: See [How to convert Bitmap to a Base64 string?](https://stackoverflow.com/questions/10889764/how-to-convert-bitmap-to-a-base64-string) – Olivier Jacot-Descombes Sep 12 '17 at 18:41
  • This looks promising. One moment – RyeGuy Sep 12 '17 at 18:41
  • All three suggestions did not work :( – RyeGuy Sep 12 '17 at 18:48
  • 1
    Have you tried step debugging in vs to see the exact line of code in which the code is failing? – Timothy Macharia Sep 12 '17 at 20:27
  • Yes I have it is failing on the instantiation of the Bitmap – RyeGuy Sep 13 '17 at 14:26
  • 1
    The Bitmap(Stream) constructor requires the stream to provide a valid image that is stored in one of the formats supported by the codecs. Like a PNG, JPEG, BMP file, etc. So definitely *not* the raw bytes in an emgu Image. Lots and lots of existing posts on how to convert an Image to a Bitmap. – Hans Passant Sep 13 '17 at 14:57
  • See my edits above. I know that it can be done but the File.ReadAllBytes is not an option in my situation. Need to pull bytes from an Emgu Image object appropriately – RyeGuy Sep 13 '17 at 15:16

1 Answers1

0

Creating a bitmap from an EmguImage did not work. Elected to save the image to disk, read all the bytes and then create a bitmap

RyeGuy
  • 4,213
  • 10
  • 33
  • 57