?
Solved

Does ImageConverter compress images?

Posted on 2011-03-22
7
Medium Priority
?
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Christian de Bellefeuille
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:Christian de Bellefeuille
ID: 35244786
? Any news
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Accepted Solution

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

Author Closing Comment

by:Christian de Bellefeuille
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:Christian de Bellefeuille
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…
Starting up a Project
Suggested Courses

765 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