PDA

View Full Version : [C#] problema screenshot per windows mobile 6


shiner88
08-05-2009, 16:22
ho un problema...

in pratica sto cercando di ottenere uno screenshot dello shermo di un'applicazione in c# per windows mobile 6...

ho trovato un paio di istruzioni in giro...solo che c'è ne una che sotto winmo non esiste...e non riesco a trovare con cosa sostituirla...

ecco il codice


private void button1_Click(object sender, EventArgs e)
{


int screenWidth = Screen.PrimaryScreen.Bounds.Right;
int screenHeight = Screen.PrimaryScreen.Bounds.Bottom;
System.Threading.Thread.Sleep(5000);
Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
//gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
// gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);


bmpScreenShot.Save("test.jpg", ImageFormat.Jpeg);


il problema ce l'ho con l'istruzione commentata...in pratica non esiste CopyFromScreen nella classe Graphics..

qualcuno ha qualche soluzione????:muro:

gugoXX
09-05-2009, 00:35
Mai fatto nulla per Windows Mobile, ma potresti provare a vedere se i vecchi metodi funzionano.

Importa le funzioni dalla user32.dll o dalla gdi32 e poi prova con

int xLoc;
int yLoc;
IntPtr dsk;
IntPtr mem;
Bitmap currentView;

//get the handle of the desktop DC
dsk = Win32API.GetDC(Win32API.GetDesktopWindow());

//create memory DC
mem = Win32API.CreateCompatibleDC(dsk);

//get the X coordinates of the screen
xLoc = Win32API.GetSystemMetrics(SCREEN_X);

//get the Y coordinates of screen.
yLoc = Win32API.GetSystemMetrics(SCREEN_Y);

//create a compatible image the size of the desktop
newBMP = Win32API.CreateCompatibleBitmap(dsk, xLoc, yLoc);

//check against IntPtr (cant check IntPtr values against a null value)
if (newBMP != IntPtr.Zero)
{
//select the image in memory
IntPtr oldBmp = (IntPtr)Win32API.SelectObject(mem, newBMP);
//copy the new bitmap into memory
Win32API.BitBlt(mem, 0, 0, xLoc, yLoc, dsk, 0, 0, SRCCOPY);
//select the old bitmap into memory
Win32API.SelectObject(mem, oldBmp);
//delete the memoryDC since we're through with it
Win32API.DeleteDC(mem);
//release dskTopDC to free up the resources
Win32API.ReleaseDC(Win32API.GetDesktopWindow(), dsk);
//create out BitMap
currentView = Image.FromHbitmap(newBMP);
//return the image
return currentView;
}


Se la user32.dll di Windows Mobile ha la GetDesktopWindow direi che sei a cavallo.

shiner88
09-05-2009, 12:10
grazie ma non funziona...mi diche che WIN32API non esiste nel contesto attuale...

se hai qualche altra dritta... :mc:

MarcoGG
09-05-2009, 13:01
grazie ma non funziona...mi diche che WIN32API non esiste nel contesto attuale...

se hai qualche altra dritta... :mc:

Qui c'è il tutorial completo :
http://www.dreamincode.net/forums/lofiversion/index.php/t34831.html