Reputation: 1984
How is an image internally stored in a byte array? While debugging in Visual Studio, I can see ASCII codes(I guess). But please someone explain it.
Say, we have an image(BLOB) stored in a table. Fetching that BLOB into a dataTable in the code(in .net) as,
byte[] image = new image();
DataTable dt = new DataTable();
dt.Columns.Add("Image", typeof(byte[]));
\\Consider the BLOB from the DB is fetched into DataTable Image column.
image = dt[Row]["Image"];
Now, how is the BLOB internally stored in byte[] image?
I've searched in the internet but couldn't find anything.
Upvotes: 1
Views: 3440
Reputation: 116118
I am not sure what is not clear for you but maybe this code can help
MemoryStream m = new MemoryStream();
Image img = Image.FromFile(file);
img.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bytes = m.ToArray();
m.Position = 0;
Image img2 = Image.FromStream(m);
Upvotes: 2
Reputation: 18662
An image is usually an array of colors encoded by a certain algorithm in a file. I am familiar with GIF image format. Look at the picture below to see an example where a red colored "V" is stored in a white colored background. The image width in this example could be 7 pixels and height would be 4 pixels. Every image always has a color table indicating the number of colors used in the image. The R marked pixels are the red ones and the w marked pixels are white colored.
RwwwwwR
wRwwwRw
wwRwRww
wwwRwww
Each pixel is an integer 32 bit wide to tell the r(red)g(green)b(blue) components and a transparency component.
Upvotes: 1
Reputation: 10184
Any image is merely a sequence of bytes structured in accordance with whatever underlying format used to represent it, eg color data, layers, dimensions, etc. The significance of any byte(s) you see during debugging is entirely dependent upon the native format of the image, eg PNG, TIFF, JPEG, BMP, etc.
Hope that's what you were looking for. If you're needing something more specific, please amend your original post and perhaps someone can give you more detail.
Upvotes: 4