Link to home
Start Free TrialLog in
Avatar of Christian de Bellefeuille
Christian de BellefeuilleFlag for Canada

asked on

Does ImageConverter compress images?

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
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

What code do you use to get the array of bytes ?
Avatar of Christian de Bellefeuille

ASKER

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

? Any news
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
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 ?
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()