110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace DeviceApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= 1000; i++)
{
string fileName = string.Format("SDMMC\\IMAGE\\{0}.jpg",i);
GetImage(fileName);
}
MessageBox.Show("Hello");
}
public void GetImage(string fileName)
{
int iHeight = Screen.PrimaryScreen.Bounds.Height;
int iWidth = Screen.PrimaryScreen.Bounds.Width;
IntPtr dc1 = WINAPI.CreateDC(null, null, null, (IntPtr)null);
Graphics gScreen = Graphics.FromHdc(dc1);
Bitmap iGetPhoto = new Bitmap(
iWidth
, iHeight);
Graphics gPhoto = Graphics.FromImage(iGetPhoto);
IntPtr iHandle = gScreen.GetHdc();
IntPtr iPhoto = gPhoto.GetHdc();
WINAPI.BitBlt(iPhoto, 0, 0, iWidth, iHeight,
iHandle, 0, 0, WINAPI.SRCCOPY);
iGetPhoto.Save(fileName, ImageFormat.Jpeg);
gScreen.ReleaseHdc(iHandle);
gPhoto.ReleaseHdc(iPhoto);
gScreen.Dispose();
gPhoto.Dispose();
iGetPhoto.Dispose();
WINAPI.DeleteDC(dc1);
}
}
public class WINAPI
{
public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter
[System.Runtime.InteropServices.DllImportAttribute("coredll.dll")]
public static extern IntPtr CreateDC(
string lpszDriver, // 驱动名称
string lpszDevice, // 设备名称
string lpszOutput, // 无用,可以设定位"NULL"
IntPtr lpInitData // 任意的打印机数据
);
[DllImport("coredll.dll")]
public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest,
int nWidth, int nHeight, IntPtr hObjectSource,
int nXSrc, int nYSrc, int dwRop);
[DllImport("coredll.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth,
int nHeight);
[DllImport("coredll.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("coredll.dll")]
public static extern bool DeleteDC(IntPtr hDC);
[DllImport("coredll.dll")]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport("coredll.dll")]
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
}
}