Solved

Does ImageConverter compress images?

Posted on 2011-03-22
7
327 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

791 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