图像如何保存? use classes in System.Drawing, for example, Image or Bitmap class has a Save method 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Image,Bitmap都有Save方法的﹐你看看SDK文檔就知道了 具体问题是这样的:我先将图片1画在窗口,然后取其中心位置再将图片2画上。现在我不知如何取得对象,如何保存?我的程序如下,请思归指点。using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace picturesaddin{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { /// <summary> /// 必需的设计器变量。 /// </summary> /// private Image backImage; private Image photoImage; private Rectangle photoRect; private Point midPoint; private const int ImageX=500; private const int ImageY=500; private const int ImageX1=400; private const int ImageY1=400; private System.Windows.Forms.Button button1; private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(352, 64); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "保存"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(448, 365); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1}); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = "Form1"; this.Text = "Form1"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form_Paint); this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void DrawImage(Graphics g) { backImage=Image.FromFile(@"C:\WINNT\FeatherTexture.bmp"); int nWidth=backImage.Width; int nHeight=backImage.Height; Rectangle destRect=new Rectangle(midPoint.X-ImageX/2,midPoint.Y-ImageY/2,ImageX,ImageY); g.DrawImage(backImage,destRect,0,0,nWidth,nHeight,GraphicsUnit.Pixel); } private void Form_Paint(object sender,System.Windows.Forms.PaintEventArgs e) { Graphics g=e.Graphics; midPoint.X=this.Width/2; midPoint.Y=this.Height/2; DrawImage(g); OverideImage(g); } private void OverideImage(Graphics g) { photoImage=Image.FromFile(@"C:\WINNT\Coffee Bean.bmp"); int nWidth=photoImage.Width; int nHeight=photoImage.Height; photoRect=new Rectangle(midPoint.X-ImageX1/2,midPoint.Y-ImageY1/2,ImageX1,ImageY1); g.DrawImage(photoImage,photoRect,0,0,nWidth,nHeight,GraphicsUnit.Pixel); } private void button1_Click(object sender, System.EventArgs e) { backImage.Save(@"c:\1.bmp"); } }} 你是说图层那种啊???我的方法是定义一个结构[Serializable()] struct layoutBmp{int lay;//记录图层Graphs[] gA; //图象数组}然后序列化嘛. Bitmap bitmap=new Bitmap(@"C:\WINNT\FeatherTexture.bmp");Graphics grfx = Graphics.FromImage(bitmap);grfx.DrawImage(photoImage,photoRect);grfx.Dispose();bitmap.Save(@"c:\1.bmp"); 求助紧急:updata时候提示Insert Info语句语法错误 这样触发button点击事件为什么不行 请教C# 正则表达式替换 多线程数据采:服务器提交协议冲突 Section=ResponseStatusLine 问一个数学问题) 背景图片很满 请问如何才能把ArcXML文档中的乱码字符转成中文 如何用C#实现网络路径上建立文件夹? 请教划词技术的思路 ???axwebbrowse控件禁用脚本 如何在 Graphics 上将一幅彩色图像转换为灰度图像画出,其C#算法实现是怎样的? aspx中的函数参数为什么不能有默认值?
我的程序如下,请思归指点。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace picturesaddin
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
///
private Image backImage;
private Image photoImage;
private Rectangle photoRect;
private Point midPoint;
private const int ImageX=500;
private const int ImageY=500;
private const int ImageX1=400;
private const int ImageY1=400;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(352, 64);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "保存";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(448, 365);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "Form1";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form_Paint);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void DrawImage(Graphics g)
{
backImage=Image.FromFile(@"C:\WINNT\FeatherTexture.bmp");
int nWidth=backImage.Width;
int nHeight=backImage.Height;
Rectangle destRect=new Rectangle(midPoint.X-ImageX/2,midPoint.Y-ImageY/2,ImageX,ImageY);
g.DrawImage(backImage,destRect,0,0,nWidth,nHeight,GraphicsUnit.Pixel);
} private void Form_Paint(object sender,System.Windows.Forms.PaintEventArgs e)
{
Graphics g=e.Graphics;
midPoint.X=this.Width/2;
midPoint.Y=this.Height/2;
DrawImage(g);
OverideImage(g);
} private void OverideImage(Graphics g)
{
photoImage=Image.FromFile(@"C:\WINNT\Coffee Bean.bmp");
int nWidth=photoImage.Width;
int nHeight=photoImage.Height;
photoRect=new Rectangle(midPoint.X-ImageX1/2,midPoint.Y-ImageY1/2,ImageX1,ImageY1);
g.DrawImage(photoImage,photoRect,0,0,nWidth,nHeight,GraphicsUnit.Pixel);
} private void button1_Click(object sender, System.EventArgs e)
{
backImage.Save(@"c:\1.bmp");
}
}
}
[Serializable()]
struct layoutBmp{
int lay;//记录图层
Graphs[] gA; //图象数组
}然后序列化嘛.
Graphics grfx = Graphics.FromImage(bitmap);
grfx.DrawImage(photoImage,photoRect);
grfx.Dispose();
bitmap.Save(@"c:\1.bmp");