老弟在写一个截图片的程序,好几天了多没有一点进展,那位大哥帮帮忙
小弟在一个窗体里,用一个pictureBox1用来打开文件的图片,当我的鼠标,在picturebox1上单击一下就在那上面画了一个90*120的区域,并把这个区域显示在别一个picturebox中,我用g.DrawImage(我要显示的图片,Picture..rec,GraphicsUnit.Pixel);来画的,但是我要把这个区域(90*120)保存到数据库里去,我现在是把第二个picturebox的image的值取出来的保存到数据库,后来显示时,是一个完整的图片,而不是我选的(90*120)区域的那个块,请问我要怎做才能保存(90*120)区域到数据库里,---------帮帮老弟啊----------
小弟在一个窗体里,用一个pictureBox1用来打开文件的图片,当我的鼠标,在picturebox1上单击一下就在那上面画了一个90*120的区域,并把这个区域显示在别一个picturebox中,我用g.DrawImage(我要显示的图片,Picture..rec,GraphicsUnit.Pixel);来画的,但是我要把这个区域(90*120)保存到数据库里去,我现在是把第二个picturebox的image的值取出来的保存到数据库,后来显示时,是一个完整的图片,而不是我选的(90*120)区域的那个块,请问我要怎做才能保存(90*120)区域到数据库里,---------帮帮老弟啊----------
[C#] public void DrawImage(Image, Point);在指定位置并且按指定形状和大小绘制指定的 Image 对象。
[C#] public void DrawImage(Image, Point[]);在指定的位置使用原始物理大小绘制指定的 Image 对象。
[C#] public void DrawImage(Image, PointF);在指定位置并且按指定形状和大小绘制指定的 Image 对象。
[C#] public void DrawImage(Image, PointF[]);在指定位置并且按指定大小绘制指定的 Image 对象。
[C#] public void DrawImage(Image, Rectangle);……public void DrawImagePoint(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create Point for upper-left corner of image.
Point ulCorner = new Point( 100, 100);
// Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner);
}
private static extern bool BitBlt(IntPtr hdcDest,int xDest,int yDest,int wDest,int hDest,IntPtr hdcSource,int xSrc,int ySrc,int RasterOp);
保存图像的一部分代码:using (Graphics graphics = this.pictureBox1.CreateGraphics())
{
IntPtr hdc = graphics.GetHdc();
//render.DrawToDC(hdc);
Bitmap b = new Bitmap(pictureBox1.ClientSize.Width,pictureBox1.ClientSize.Height);
Graphics gDest = Graphics.FromImage(b);
IntPtr hdcMemory = gDest.GetHdc();
BitBlt( hdcMemory,0, 0,pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height, hdc,0, 0,13369376);
graphics.ReleaseHdc(hdc);
gDest.ReleaseHdc(hdcMemory);
b.Save("C:\\1.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
b.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
ScreenCapture();
MessageBox.Show("The picture will be stored at " + picPath);
} private void ScreenCapture()
{
//this.WindowState = FormWindowState.Maximized; IntPtr dcScreen = CreateDC("DISPLAY", null, null, (IntPtr)null);
Graphics grfxScreen = Graphics.FromHdc(dcScreen); Bitmap bmpScreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, grfxScreen);
Graphics grfxBmp = Graphics.FromImage(bmpScreen); //because the grahics are being using,so we must get their dc.
IntPtr dcgscreen = grfxScreen.GetHdc();
IntPtr dcgbmp = grfxBmp.GetHdc(); //copy the screen picture to bitmap.
BitBlt(dcgbmp, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height,
dcgscreen, 0, 0, 13369376); //release all the resources.must be release them before bitblt method.
grfxBmp.ReleaseHdc(dcgbmp);
grfxScreen.ReleaseHdc(dcgscreen);
//Draw cursor.
Cursor.Current.Draw(grfxBmp, new Rectangle(Cursor.Position, Cursor.Size));
//save the picuture.
bmpScreen.Save("Screen Capture.bmp", ImageFormat.Bmp); //release the resources
grfxBmp.Dispose();
grfxScreen.Dispose(); }