PDA

View Full Version : سوال: عکس گرفتن ار دسکتاپ



EhsanAvr
یک شنبه 01 آذر 1388, 11:21 صبح
سلام. من میخوام از صفحه عکس بگیرم.سرچ هم کردم ولی چیز به درد بخوری پیدا نکردم
یکی گفته بود که باید هندل پنجره رو با یه API بدست بیاری و سپس از اون عکس بگیری.
ولی هر کاری کردم نشد که نشد!!!! دوستان اگه یه سورس نمونه بزارن ممنون میشم.

taeb1986
یک شنبه 01 آذر 1388, 12:45 عصر
ببین فکر کنم این source code به دردت بخوره. البته باید یه enum تعریف کنی که موراد case های داخل switch رو داشته باشه.موقع فراخوان تابع هم اگه بخوای از کل صفحه عکس بگیری بایدباپارامتر primary screenفراخوانی کنی.

taeb1986
یک شنبه 01 آذر 1388, 12:51 عصر
public Bitmap[] Capture( CaptureType typeOfCapture )
{
// used to capture then screen in memory
Bitmap memoryImage;
// number of screens to capture,
// will be updated below if necessary
int count = 1;

try
{
Screen[] screens = Screen.AllScreens;
Rectangle rc;

// setup the area to capture
// depending on the supplied parameter
switch ( typeOfCapture )
{
case CaptureType.PrimaryScreen:
rc = Screen.PrimaryScreen.Bounds;
break;
case CaptureType.VirtualScreen:
rc = SystemInformation.VirtualScreen;
break;
case CaptureType.WorkingArea:
rc = Screen.PrimaryScreen.WorkingArea;
break;
case CaptureType.AllScreens:
count = screens.Length;
typeOfCapture = CaptureType.WorkingArea;
rc = screens[0].WorkingArea;
break;
default:
rc = SystemInformation.VirtualScreen;
break;
}
// allocate a member for saving the captured image(s)
images = new Bitmap[count];

// cycle across all desired screens
for ( int index = 0; index < count; index++ )
{
if ( index > 0 )
rc = screens[index].WorkingArea;
// redefine the size on multiple screens

memoryImage = new Bitmap( rc.Width, rc.Height,
PixelFormat.Format32bppArgb );
using ( Graphics memoryGrahics =
Graphics.FromImage( memoryImage ) )
{
// copy the screen data
// to the memory allocated above
memoryGrahics.CopyFromScreen( rc.X, rc.Y,
0, 0, rc.Size, CopyPixelOperation.SourceCopy );
}
images[index] = memoryImage;
// save it in the class member for later use
}
}
catch ( Exception ex )
{
// handle any erros which occured during capture
MessageBox.Show( ex.ToString(), "Capture failed",
MessageBoxButtons.OK, MessageBoxIcon.Error );
}
return images;
}