Solved

Does ImageConverter compress images?

Posted on 2011-03-22
7
318 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
Comment Utility
What code do you use to get the array of bytes ?
0
 
LVL 10

Author Comment

by:cdebel
Comment Utility
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
Comment Utility
? Any news
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 44

Accepted Solution

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

Author Closing Comment

by:cdebel
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

743 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

16 Experts available now in Live!

Get 1:1 Help Now