Save Screenshot to jpg

V

verenadoll

Hello NG,

i want to take a screenshot of my device and save it as jpg-file. i
want to do this in vb.net (2008) and compactframework 3.5 . i dont
want to use external tools.

the device is motorola mc5590.

Maybe someone has an example for me?

Regards, Verena
 
C

Carsten Unterberg

Hi Verena,
Hello NG,

i want to take a screenshot of my device and save it as jpg-file. i
want to do this in vb.net (2008) and compactframework 3.5 . i dont
want to use external tools.

the device is motorola mc5590.

Maybe someone has an example for me?


it is really simple. It is just one P/Invoke command, the rest is plain
..Net.
You just need to invoke the "BitBlt"-function from "coredll.dll".

[DllImport("coredll.dll")]
public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int
nWidth, int nHeight, IntPtr hdcSrc, int nXsrc, int dwRop);


public static function Bitmap GetSnapshot(Control control)
{

//checking control
if (control == null)
{

//exit
return null;

}

//create a graphics object for control
Graphics cgraphics = control.CreateGraphics();

//create a bitmap of controls' size
Bitmap snapshot = new Bitmap(control.Size.Width, control.Size.Height);

//create a graphics object for snapshot
Graphics sgraphics = Graphics.FromImage(snapshot);

//make snapshot from control
BitBlt(sgraphics.GetHDC(), 0, 0, snapshot.Size.Width, snapshot.Size.Height,
cgraphics.GetHdc(), 0 - control.Location.Left, 0 - control.Location.Top,
0XCC0020);


//disposing the graphics objects
cgraphics.Dispose();
sgraphics.Dispose();

//set return value
return snapshot;

}


Fell free to ask, if you might have any questions.

Regards,

Carsten Unterberg | Test-Framework
http://test-framework.blogspot.com/
BitBlt(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Change Key 2
Install CAB File 1
Set File Time 3
Stop Debugger --> Event 1
Write log file using Thread 16
Create WLAN profile (Symbol MC55) 1
Visual Studio IDE Problem with Compact Framework 3.5 1
Screenshot to .JPG 9

Top