Solved

Does ImageConverter compress images?

Posted on 2011-03-22
7
324 Views
Last Modified: 2012-05-11
We are using GetDesktopWindow to take a snapshot of the screen, and we tried to use the ImageConverter to produce an array of bytes.  For some reason, for a screen with absolutely no change on it, the lenght of the array produced by the ImageConverter is not the same.

Anyone got an explanation for that?

Does anyone know if ImageConverter is supposed to compress our image?  Is it the Bitmap object itself who is responsible for this result?

thanks for the info
0
Comment
Question by:cdebel
  • 4
  • 3
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35196402
What code do you use to get the array of bytes ?
0
 
LVL 10

Author Comment

by:cdebel
ID: 35197666
Here's the piece of code.  You should see the conversion at line 24.

I've a resolution of 1920x1200x32 bits, and the resulting array seems to be 100K-200K lenght.  If it's really uncompressed, it should be much more than that.  or there's something i don't understand.
if i use a DeflateStream on this buffer, sometime it compress a little bit (like 1-5%), and sometime the result is worse than if i didn't compressed the image!

        public Bitmap GetDesktop()
        {
            Size c = SystemInformation.PrimaryMonitorSize;
            Bitmap bmp;
            IntPtr dc1;
            IntPtr dc2;
            Graphics g;

            ImageConverter converter = new ImageConverter();
            CompressionTest.CompressStream oCS = new CompressStream();
            byte[] mBuf;

            bmp = new Bitmap(c.Width, c.Height);
            g = Graphics.FromImage(bmp);
            dc1 = g.GetHdc();
            dc2 = GetDC(GetDesktopWindow());

            BitBlt(dc1, 0, 0, c.Width, c.Height, dc2, 0, 0, SRCCOPY);
            
            g.ReleaseHdc(dc1);
            ReleaseDC(GetDesktopWindow(), dc2);
            g.Dispose();

            mBuf = (byte[])converter.ConvertTo(bmp, typeof(byte[]));

            // Here i would do some compression using the DeflateStream, 
            // but doesn't seems to compress anymore.

            return bmp;
        }

Open in new window

0
 
LVL 10

Author Comment

by:cdebel
ID: 35244786
? Any news
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 35249902
No, I don't see why that should result in any compression.
0
 
LVL 10

Author Closing Comment

by:cdebel
ID: 35302401
To my eyes this question was not really answered,
Since no tests have been done to see if if my code was wrong.

Not any explanations about what could cause such a small KB for a whole screen snapshot.  Might be bitblt?  I don't know...
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35306115
BitBlt ought to just copy without modifying, have you actually checked what c.Width and c.Height are ?
How do you determine the length of the array returned ?
0
 
LVL 10

Author Comment

by:cdebel
ID: 35310385
It's in the code i already gave, and as i've mentionned, it's 1920x1200.  I've double checked in the debugger, but the height & width match the 1920x1200.
Size c = SystemInformation.PrimaryMonitorSize;

Open in new window


And for the lenght, well, it's quite easy...

mBuf.Lenght()
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now