1

I have a byte array which contains an image; I converted the image to byte array using this method:

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
 MemoryStream ms = new MemoryStream();
 imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
 return  ms.ToArray();
}

This is the byte array:

Bitmap bmp =  Image.FromFile("xxx");
byte[] buffer = ImageToByteArray(bmp);

Now I would like to add some minor minor information about the image in the byte array,such as the position it should be drawn to,etc.

How could it be done? Lets say i want to add these 2 values:1209,540.

1
  • 1
    If you want to convert "int" to byte and then append them to the memory stream, you could use the BinaryWriter: writer = new BinaryWriter(ms); writer.Write((int)1209); writer.Write((int)540); Commented Aug 14, 2015 at 12:00

1 Answer 1

0

First I don't think you can use these values 1209,540 since byte's max val is 255.

But if your values are between that range 0-255, why don't you add two bytes at the end of the array and when the conversion is to be made remove the last two values?

Sign up to request clarification or add additional context in comments.

2 Comments

would'nt it be posibble to convert these values to byte type?
@Slashy No, an unsigned can store from 0 to 255. The other way would be to wrap this array in a class where you'd declare another property containing the extra values you'd like to pass!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.