PDA

View Full Version : سوال: عکس گرفتن از محیط نرم افزار



h.rezaee
چهارشنبه 28 تیر 1391, 22:22 عصر
سلام بر دوستان حرفه ای. می خواستم بدونم چه جوری یه برنامه نوشت که از فیلم بشه عکس بگیری؟ یعنی یه مدیا پلیر قرار بدیم که بشه از فیلمی که اون پخش میکنه عکس بگیره؟

abdullah20
چهارشنبه 28 تیر 1391, 23:13 عصر
اخرش عکس گرفتن از محیط نرم افزار یا فیلم؟

h.rezaee
چهارشنبه 28 تیر 1391, 23:36 عصر
اخرش عکس گرفتن از محیط نرم افزار یا فیلم؟
میخوام یه مدیا پلیر تو یه قسمت از برنامه استفاده کنم که بشه از اون عکس گرفت.

ali_habibi1384
پنج شنبه 29 تیر 1391, 00:50 صبح
شما ميخواي Print Screen بگيري :


/// <summary>
/// This class shall keep the GDI32 APIs used in our program.
/// </summary>
public class PlatformInvokeGDI32
{
#region Class Variables
public const int SRCCOPY = 13369376;
#endregion
#region Class Functions<br>
[DllImport("gdi32.dll",EntryPoint="DeleteDC")]
public static extern IntPtr DeleteDC(IntPtr hDc);

[DllImport("gdi32.dll",EntryPoint="DeleteObject")]
public static extern IntPtr DeleteObject(IntPtr hDc);

[DllImport("gdi32.dll",EntryPoint="BitBlt")]
public static extern bool BitBlt(IntPtr hdcDest,int xDest,
int yDest,int wDest,int hDest,IntPtr hdcSource,
int xSrc,int ySrc,int RasterOp);

[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleBitmap")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,
int nWidth, int nHeight);

[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleDC")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

[DllImport ("gdi32.dll",EntryPoint="SelectObject")]
public static extern IntPtr SelectObject(IntPtr hdc,IntPtr bmp);
#endregion

#region Public Constructor
}

/// <summary>
/// This class shall keep the User32 APIs used in our program.
/// </summary>
public class PlatformInvokeUSER32
{
#region Class Variables
public const int SM_CXSCREEN=0;
public const int SM_CYSCREEN=1;
#endregion

#region Class Functions
[DllImport("user32.dll", EntryPoint="GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);

[DllImport("user32.dll",EntryPoint="GetSystemMetrics")]
public static extern int GetSystemMetrics(int abc);

[DllImport("user32.dll",EntryPoint="GetWindowDC")]
public static extern IntPtr GetWindowDC(Int32 ptr);

[DllImport("user32.dll",EntryPoint="ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDc);

#endregion
}

/// <summary>
/// This class shall keep all the functionality
/// for capturing the desktop.
/// </summary>
public class CaptureScreen
{
#region Class Variable Declaration
protected static IntPtr m_HBitmap;
#endregion

///
/// This class shall keep all the functionality for capturing
/// the desktop.
///
public class CaptureScreen
{
#region Public Class Functions
public static Bitmap GetDesktopImage()
{
//In size variable we shall keep the size of the screen.
SIZE size;

//Variable to keep the handle to bitmap.
IntPtr hBitmap;

//Here we get the handle to the desktop device context.
IntPtr hDC = PlatformInvokeUSER32.GetDC
(PlatformInvokeUSER32.GetDesktopWindow());

//Here we make a compatible device context in memory for screen
//device context.
IntPtr hMemDC = PlatformInvokeGDI32.CreateCompatibleDC(hDC);

//We pass SM_CXSCREEN constant to GetSystemMetrics to get the
//X coordinates of the screen.
size.cx = PlatformInvokeUSER32.GetSystemMetrics
(PlatformInvokeUSER32.SM_CXSCREEN);

//We pass SM_CYSCREEN constant to GetSystemMetrics to get the
//Y coordinates of the screen.
size.cy = PlatformInvokeUSER32.GetSystemMetrics
(PlatformInvokeUSER32.SM_CYSCREEN);

//We create a compatible bitmap of the screen size and using
//the screen device context.
hBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap
(hDC, size.cx, size.cy);

//As hBitmap is IntPtr, we cannot check it against null.
//For this purpose, IntPtr.Zero is used.
if (hBitmap!=IntPtr.Zero)
{
//Here we select the compatible bitmap in the memeory device
//context and keep the refrence to the old bitmap.
IntPtr hOld = (IntPtr) PlatformInvokeGDI32.SelectObject
(hMemDC, hBitmap);
//We copy the Bitmap to the memory device context.
PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0,size.cx,size.cy, hDC,
0, 0,PlatformInvokeGDI32.SRCCOPY);
//We select the old bitmap back to the memory device context.
PlatformInvokeGDI32.SelectObject(hMemDC, hOld);
//We delete the memory device context.
PlatformInvokeGDI32.DeleteDC(hMemDC);
//We release the screen device context.
PlatformInvokeUSER32.ReleaseDC(PlatformInvokeUSER3 2.
GetDesktopWindow(), hDC);
//Image is created by Image bitmap handle and stored in
//local variable.
Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap);
//Release the memory to avoid memory leaks.
PlatformInvokeGDI32.DeleteObject(hBitmap);
//This statement runs the garbage collector manually.
GC.Collect();
//Return the bitmap
return bmp;
}
//If hBitmap is null, retun null.
return null;
}
#endregion
}

//This structure shall be used to keep the size of the screen.
public struct SIZE
{
public int cx;
public int cy;
}

h.rezaee
پنج شنبه 29 تیر 1391, 01:34 صبح
شما ميخواي Print Screen بگيري :


/// <summary>
/// This class shall keep the GDI32 APIs used in our program.
/// </summary>
public class PlatformInvokeGDI32
{
#region Class Variables
public const int SRCCOPY = 13369376;
#endregion
#region Class Functions<br>
[DllImport("gdi32.dll",EntryPoint="DeleteDC")]
public static extern IntPtr DeleteDC(IntPtr hDc);

[DllImport("gdi32.dll",EntryPoint="DeleteObject")]
public static extern IntPtr DeleteObject(IntPtr hDc);

[DllImport("gdi32.dll",EntryPoint="BitBlt")]
public static extern bool BitBlt(IntPtr hdcDest,int xDest,
int yDest,int wDest,int hDest,IntPtr hdcSource,
int xSrc,int ySrc,int RasterOp);

[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleBitmap")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,
int nWidth, int nHeight);

[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleDC")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

[DllImport ("gdi32.dll",EntryPoint="SelectObject")]
public static extern IntPtr SelectObject(IntPtr hdc,IntPtr bmp);
#endregion

#region Public Constructor
}

/// <summary>
/// This class shall keep the User32 APIs used in our program.
/// </summary>
public class PlatformInvokeUSER32
{
#region Class Variables
public const int SM_CXSCREEN=0;
public const int SM_CYSCREEN=1;
#endregion

#region Class Functions
[DllImport("user32.dll", EntryPoint="GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);

[DllImport("user32.dll",EntryPoint="GetSystemMetrics")]
public static extern int GetSystemMetrics(int abc);

[DllImport("user32.dll",EntryPoint="GetWindowDC")]
public static extern IntPtr GetWindowDC(Int32 ptr);

[DllImport("user32.dll",EntryPoint="ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDc);

#endregion
}

/// <summary>
/// This class shall keep all the functionality
/// for capturing the desktop.
/// </summary>
public class CaptureScreen
{
#region Class Variable Declaration
protected static IntPtr m_HBitmap;
#endregion

///
/// This class shall keep all the functionality for capturing
/// the desktop.
///
public class CaptureScreen
{
#region Public Class Functions
public static Bitmap GetDesktopImage()
{
//In size variable we shall keep the size of the screen.
SIZE size;

//Variable to keep the handle to bitmap.
IntPtr hBitmap;

//Here we get the handle to the desktop device context.
IntPtr hDC = PlatformInvokeUSER32.GetDC
(PlatformInvokeUSER32.GetDesktopWindow());

//Here we make a compatible device context in memory for screen
//device context.
IntPtr hMemDC = PlatformInvokeGDI32.CreateCompatibleDC(hDC);

//We pass SM_CXSCREEN constant to GetSystemMetrics to get the
//X coordinates of the screen.
size.cx = PlatformInvokeUSER32.GetSystemMetrics
(PlatformInvokeUSER32.SM_CXSCREEN);

//We pass SM_CYSCREEN constant to GetSystemMetrics to get the
//Y coordinates of the screen.
size.cy = PlatformInvokeUSER32.GetSystemMetrics
(PlatformInvokeUSER32.SM_CYSCREEN);

//We create a compatible bitmap of the screen size and using
//the screen device context.
hBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap
(hDC, size.cx, size.cy);

//As hBitmap is IntPtr, we cannot check it against null.
//For this purpose, IntPtr.Zero is used.
if (hBitmap!=IntPtr.Zero)
{
//Here we select the compatible bitmap in the memeory device
//context and keep the refrence to the old bitmap.
IntPtr hOld = (IntPtr) PlatformInvokeGDI32.SelectObject
(hMemDC, hBitmap);
//We copy the Bitmap to the memory device context.
PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0,size.cx,size.cy, hDC,
0, 0,PlatformInvokeGDI32.SRCCOPY);
//We select the old bitmap back to the memory device context.
PlatformInvokeGDI32.SelectObject(hMemDC, hOld);
//We delete the memory device context.
PlatformInvokeGDI32.DeleteDC(hMemDC);
//We release the screen device context.
PlatformInvokeUSER32.ReleaseDC(PlatformInvokeUSER3 2.
GetDesktopWindow(), hDC);
//Image is created by Image bitmap handle and stored in
//local variable.
Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap);
//Release the memory to avoid memory leaks.
PlatformInvokeGDI32.DeleteObject(hBitmap);
//This statement runs the garbage collector manually.
GC.Collect();
//Return the bitmap
return bmp;
}
//If hBitmap is null, retun null.
return null;
}
#endregion
}

//This structure shall be used to keep the size of the screen.
public struct SIZE
{
public int cx;
public int cy;
}

ممنون از شما. ولی این کلاس از کل دسکتاپ عکس میگیره. بنده میخوام فقط از فیلم در حال پخش مدیا پلیری که تو برنامه قرار دادیم عکس بگیره.

ali_habibi1384
پنج شنبه 29 تیر 1391, 07:44 صبح
ممنون از شما. ولی این کلاس از کل دسکتاپ عکس میگیره. بنده میخوام فقط از فیلم در حال پخش مدیا پلیری که تو برنامه قرار دادیم عکس بگیره.
خب مگه اون توي دسك تاپ در حال پخش نيست؟

Y_Safaiee
پنج شنبه 29 تیر 1391, 08:24 صبح
با سلام خدمت شما

نمیدونم سوالتونو فهمیدم یا نه اما ساده ترین راه



System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(button1.Width, button1.Height);
button1.DrawToBitmap(bmp, button1.ClientRectangle);
bmp.Save("d:\\1.jpg");


این کد از هر کنترلی میتونه عکس بگیره فقط لازمه اون کنترل رو بهش بگید کدومه,مثلا در مثال بالا من گفتم که از باتون عکس بگیره.

موفق باشین
بایت بایت

h.rezaee
پنج شنبه 29 تیر 1391, 08:58 صبح
خب مگه اون توي دسك تاپ در حال پخش نيست؟
ببینید اگه کاربر لوکیشن پنجره رو تغییر بده اون موقع ایراد کار پیدا میشه.

Y_Safaiee
پنج شنبه 29 تیر 1391, 09:09 صبح
ببینید اگه کاربر لوکیشن پنجره رو تغییر بده اون موقع ایراد کار پیدا میشه.

با سلام مجدد,دوست خوبم کدی که من نوشتم براش مهم نیست پنجره تکون بخوره یا نه,اون از کنترل مورد نظر عکس میگیره,من خودم کدمو با تغییر سایز پنجره,مکان,کوچیک کردن کنترل تست کردم و جواب داد,حتی از مدیا پلیری که داخل فرمم هست هم عکس گرفتم.

موفق باشین
بایت بایت

h.rezaee
پنج شنبه 29 تیر 1391, 09:29 صبح
با سلام خدمت شما

نمیدونم سوالتونو فهمیدم یا نه اما ساده ترین راه



System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(button1.Width, button1.Height);
button1.DrawToBitmap(bmp, button1.ClientRectangle);
bmp.Save("d:\\1.jpg");


این کد از هر کنترلی میتونه عکس بگیره فقط لازمه اون کنترل رو بهش بگید کدومه,مثلا در مثال بالا من گفتم که از باتون عکس بگیره.

موفق باشین
بایت بایت

ممنون دوست عزیز. همونی بود که می خواستم. اما در مورد مدیا پلیر جواب نمیده

h.rezaee
پنج شنبه 29 تیر 1391, 10:30 صبح
دوست عزیز این کدها برای مدیا پلیر جواب نمیده

h.rezaee
پنج شنبه 29 تیر 1391, 14:25 عصر
با سلام مجدد,دوست خوبم کدی که من نوشتم براش مهم نیست پنجره تکون بخوره یا نه,اون از کنترل مورد نظر عکس میگیره,من خودم کدمو با تغییر سایز پنجره,مکان,کوچیک کردن کنترل تست کردم و جواب داد,حتی از مدیا پلیری که داخل فرمم هست هم عکس گرفتم.

موفق باشین
بایت بایت
ممنون از حسن توجه تون. ولی بنده این جوابی که پنجره تکون بخوره رو به دوست خوبمون علی آقا دادم.
بعد در مورد مدیا پلیر هم برای من عکس رو میندازه منتها مشکی میندازه. اگه زحمتی نیست و مرحمت بفرمایید اون برنامه رو بزارید یک دنیا ممنون میشم.

yashar666
پنج شنبه 29 تیر 1391, 16:10 عصر
using System.Drawing.Imaging;
using System.Threading;

Bitmap bmp = new Bitmap(Screen.PrimaryScreen.WorkingArea.Size.Width , Screen.PrimaryScreen.WorkingArea.Size.Height, PixelFormat.Format32bppArgb);
private void button1_Click(object sender, EventArgs e)
{

this.Hide();
Graphics gr = Graphics.FromImage(bmp);
Size size = Screen.PrimaryScreen.WorkingArea.Size ;
Thread.Sleep(200);
gr.CopyFromScreen(0, 0, -1, -1, size, CopyPixelOperation.SourceCopy);
pictureBox1.Image = bmp;
Show();
bmp.Save("c:\\a.bmp");


}

موفق باشید

h.rezaee
پنج شنبه 29 تیر 1391, 23:06 عصر
using System.Drawing.Imaging;
using System.Threading;

Bitmap bmp = new Bitmap(Screen.PrimaryScreen.WorkingArea.Size.Width , Screen.PrimaryScreen.WorkingArea.Size.Height, PixelFormat.Format32bppArgb);
private void button1_Click(object sender, EventArgs e)
{

this.Hide();
Graphics gr = Graphics.FromImage(bmp);
Size size = Screen.PrimaryScreen.WorkingArea.Size ;
Thread.Sleep(200);
gr.CopyFromScreen(0, 0, -1, -1, size, CopyPixelOperation.SourceCopy);
pictureBox1.Image = bmp;
Show();
bmp.Save("c:\\a.bmp");


}

موفق باشید
دوست عزیز این هم از کل دسکتاپ عکس میگیره.

روشی که دوست قبلی مون گفته بود در مورد تمامی کنترل ها جواب میده به جز مدیا پلیر کداشو میزارم دیدن و پیدا کردن ایراداش خالی از لطف شما حرفه ای ها نیست
http://uplod.ir/files/5/z151w24t5qrdv3/WindowsFormsApplication2.rar

yashar666
جمعه 30 تیر 1391, 00:32 صبح
اینو من از کجا دانلود کنم؟؟؟؟؟؟؟؟؟

yashar666
جمعه 30 تیر 1391, 00:37 صبح
این کد که من نوشتم از همه کنترل ها عکس میگیره

h.rezaee
چهارشنبه 04 مرداد 1391, 00:55 صبح
اینو من از کجا دانلود کنم؟؟؟؟؟؟؟؟؟
دوست عزیز لینک دانلود قرار داده شده