This project has moved. For the latest updates, please go here.

Alternatives to Format32bbArgb

Feb 27, 2011 at 11:15 PM

Hi, I have an app that creates an Excel with several images in them. Based from the examples I use the following code:

 

Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);
ExcelPicture ScreenshotSave = getWorksheet.Drawings.AddPicture("Screenshot " + x + DateTime.Now, bmpScreenshot);
ScreenshotSave.SetSize(2);
ScreenshotSave.SetPosition(x, 1, 3, 1);

The screenshots are real clear and can be resized without loss in details, however, it consumes so much space that the Excel file that will be appended can reach 20MB in no time, around which I get to experience frequent System.OutofMemory exceptions already.

Tried changing the format from Format32bppArgb to others (such as Grayscale or 8 bit) just to compensate, but it appears the OutofMemory exception becomes worse.

I was wondering if there are other ways of adding screenshots onto the Excel file without using a bitmap format? Or alternatively bitmap format but significantly lesser in terms of file size consumption. Loss of detail and colors wouldn't matter, the priority is to keep the file size of the Excel small and portable.

Any thoughts? :)

Coordinator
Feb 28, 2011 at 5:54 AM

Hi,

The image is saved as a jpg internally, so it should not take that much space. I suggest you shrink it before you add add it.

Jan

Feb 28, 2011 at 6:08 AM

Hi Jan,

Thanks for your response. However that doesn't seem to be the case... if I take seven screenshots manually and save it as JPEG via Paint, I only get about ~500KB. However, if I run the code above for the same seven screenshots, the file size ramps up to ~3MB.

When you say shrink, do you mean SetSize? Or something else? I tried altering the PixelFormat property from the instantiated bitmap but I get issues as well as posted.

Feb 28, 2011 at 10:22 PM

Just to add, the images saved are screenshots taken at a particular execution of a code. I changed the resolution of my screen to 800x600 in hope of lessening the file size consumption but the decrease in file size is not substantial enough to lessen the overall size of the Excel file..