Reputation: 23
When generating Bitmaps from a WebBrowser's DrawToBitmap() function, while using two images of the same size, why in certain instances, when converting the Bitmap to a byte array, do you have arrays of different sizes? The function I used:
public static byte[] ImageToByte(Image img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
From here there is a problem with the images I use. They are different, I use snapshots of http://www.google.com and http://www.google.co.uk. They both generate images with a size of {Width = 833 Height = 500}. However, the sizes of the byte arrays are 20072 and 24368 respectively.
Any ideas?
Thanks!
EDIT
Let me add some more information. The images are turned into BMPs. I'll attach some more of my janked up C# for you all to understand a bit more.
public void captureSnapshot(string url)
{
this.url = url;
var thr = new Thread(() =>
{
browser = new WebBrowser();
browser.DocumentCompleted += snapshotEventCompleted;
browser.Navigate(url);
Application.Run();
});
thr.SetApartmentState(ApartmentState.STA);
thr.Start();
}
public void snapshotEventCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
int pageHeight = browser.Document.Body.ScrollRectangle.Height;
int pageWidth = browser.Document.Body.ScrollRectangle.Width;
snapshot = new Bitmap(pageWidth, pageHeight);
browser.Size = new Size(pageWidth, pageHeight);
browser.ScrollBarsEnabled = false;
browser.DrawToBitmap(snapshot, new Rectangle(browser.Location.X, browser.Location.Y, pageWidth, pageHeight));
}
SOLVED:
So it turns out the function DrawToBitmap is not supported. womp
Upvotes: 0
Views: 254
Reputation: 292345
It depends on the codec used to save the image. If it's PNG or JPG for instance, then the compression might produce outputs of different sizes for images of the same size. That's because large uniform areas are compressed much more efficiently than areas with lots of details.
Upvotes: 3
Reputation: 1449
It's because of something called Stride
please take a look at this article : Image Stride
Two buffers that contain video frames with equal dimensions can have two different strides. If you process a video image, you must take the stride into account.
Upvotes: 2