我近日在做一个实习题目要写一个类似于Windows下画笔的东东,快写好了,不过不知道如何将自己画在客户区的图形保存.........各位大虾知道的请回一个,谢了~~
解决方案 »
- C# 凹凸按键实现颜色的选择
- 急!!!数据源的类型无效
- d在Form中用WebBrowser打开Excel后,能否再另外用Excel打开其他文件
- 用GDI画图,我想把每个图象的轮廓线保存起来应该怎么办,一个图象的轮廓线包括线段和狐线段.
- VS 2008 绑定数据源时报错
- c#中怎么操作word 和word 中的公式
- 怎么将json中d前缀去掉
- C# winfrom combobox 有2个combobox
- 怎么提取windows字体库?
- 怎么样把查询结果显示在gridview中??
- 怎么控制其他.exe程序开启其对应的文件.
- 求visual studio .net 2003下好用的表格控件(Form开发)
http://www.codeproject.com/csharp/DrawTools/DrawTools_src.zip
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我用这种方法保存后出现的图片是一张黑图..........为什么呀??
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
这种方法创建的因该是一张和目标Graphics相同分辨率的图片,当然是没有内容的黑图了~~
要怎么做我也很想知道~~~~
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
memoryImage.Save("c:\\aa.bmp");
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
using System.Drawing;
直接运行下面的程序:
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Drawing.Text;
namespace Caculator
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
using(Bitmap img = new Bitmap(800,800))
{
using(Graphics g = Graphics.FromImage(img))
{ Pen WhitePen=new Pen(Color.White,1);
g.DrawEllipse(WhitePen,150,150,500,500);
}
img.Save("D:\\e.gif",ImageFormat.Gif);
} } /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components=new System.ComponentModel.Container();
this.Size=new System.Drawing.Size(300,300);
this.Text="Display At Starup";
this.BackColor=Color.White;
}
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{ Application.Run(new Form1());
}
}
}
至于"wfhlxl(光明正大地偷......学)"的方法,其中的
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
该是自己定义的一个函数吧?我在msdn中没有查到呀?
再来人呀,我再添分~~~~
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
memoryImage.Save("c:\\aa.jpg",System.Drawing.Imaging.ImageFormat.Jpeg); }
能给解释一下BitBlt这个函数是怎么回事吗??它好像是GDI里面的一个函数,不是GDI+里的
我再加20分~~
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;namespace testsaveimage
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} int i = 5;//画线用的
System.Drawing.Bitmap image = null;//建立一个实例
private void button1_Click(object sender, EventArgs e)
{
Graphics g = Graphics.FromImage(pictureBox1.Image); g.DrawLine(Pens.Gold,10+i,10,110,10+i);
i += 10;
this.pictureBox1.Refresh();
g.Dispose();
} private void button2_Click(object sender, EventArgs e)
{
this.pictureBox1.Image.Save(@"c:\test.jpg", ImageFormat.Gif); } private void Form1_Load(object sender, EventArgs e)
{
this.pictureBox1.Controls.Clear();
image = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
Graphics.FromImage(image).Clear(Color.White);//消除底图的黑色
this.pictureBox1.Image = (Bitmap)image.Clone();//这句话是关键
} }
}
我这还有一个很好的实例,是从www.codeproject.com下的,需要的话可以给你发过去