标签:c# picturebox bitmap 图像保存
1 Picturebox控件
主要用于显示、保存图形图像信息。其属性及方法如下
|
属性 |
说明 |
|
Image |
设置或获取与该控件显示的图像 |
|
SizeMode |
指示如何显示图像,其中StretchImage自动适应大小 |
|
方法 |
说明 |
|
Load |
显示图像 |
|
Image.Save |
保存图像 |
2 Bitmap类
|
Size |
获取图像的大小。 |
|
Width |
图像宽度 |
|
Height |
图像高度 |
|
FromFile |
从指定的文件创建图像 |
|
FromStream |
从指定的数据流创建图像 |
|
GetPixel |
获取此Bitmap中指定像素的颜色 |
|
MakeTransparent |
使默认的透明色对此Bitmap透明 |
|
Save |
保存图像 |
|
RotateFlip |
旋转,翻转 |
3 案例,如图
4 代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 图形控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string _imageFilePath = string.Empty;
private void addPicture_Click(object sender, EventArgs e)
{
OpenFileDialog file = new OpenFileDialog();
file.InitialDirectory = ".";
file.Filter = "所有文件(*.*)|*.*";
file.ShowDialog();
if(file.FileName != string.Empty)
{
try
{
_imageFilePath = file.FileName;
this.pictureBox1.Load(_imageFilePath);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void savePictureButton_Click(object sender, EventArgs e)
{
SaveFileDialog save = new SaveFileDialog();
save.ShowDialog();
if(save.FileName != string.Empty)
{
pictureBox1.Image.Save(save.FileName);
}
}
private void addMarkButton_Click(object sender, EventArgs e)
{
try
{
Graphics gra = Graphics.FromImage(this.pictureBox1.Image);
Font font = new Font("隶书", 80, FontStyle.Bold);
Pen pen = new Pen(Color.OrangeRed);
gra.DrawString("世界,你好!", font, pen.Brush, 0, 0);
pen.Dispose();
gra.Dispose();
this.pictureBox1.Refresh();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
标签:c# picturebox bitmap 图像保存
原文地址:http://blog.csdn.net/taoerit/article/details/42613505