111,086
社区成员




using System;
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 frmSxqm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Graphics g;
private int sX, sY;
private Bitmap bitmap;
private void Form1_Load(object sender, EventArgs e)
{
bitmap = new Bitmap(300, 300);
g = Graphics.FromImage(bitmap);
Cursor.Current = Cursors.Default;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
sX = e.X;
sY = e.Y;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
g.DrawLine(new Pen(Color.Black, 3), sX, sY, e.X, e.Y);
sX = e.X; sY = e.Y;
this.pictureBox1.Image = bitmap;
}
private void button1_Click(object sender, EventArgs e)
{
bitmap = new Bitmap(300, 300);
g = Graphics.FromImage(bitmap);
this.pictureBox1.Image = bitmap;
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定签名完成了吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (result == DialogResult.Cancel)
return;
else
{
string signaturePath = DateTime.Now.ToString("yyMMddHHmmssms") + ".jpg";
compressionPicture(bitmap, 300, 300, signaturePath, ImageFormat.Jpeg);
//this.Close();
}
}
private void compressionPicture(Bitmap bmap, int newWidth, int newHeight, string saveFileName, ImageFormat format)
{
Bitmap newImg = new Bitmap(newWidth, newHeight);
Rectangle srcRec = new Rectangle(0, 0, bmap.Width, bmap.Height);
Rectangle destRec = new Rectangle(0, 0, newWidth, newHeight);
Graphics g = Graphics.FromImage(newImg);
g.DrawImage(bmap, destRec, srcRec, GraphicsUnit.Pixel);
newImg.Save(saveFileName, format);
}
}
}
string signaturePath = DateTime.Now.ToString("yyMMddHHmmssms") + ".png";
compressionPicture(bitmap, 300, 300, signaturePath, ImageFormat.Png);
private void button1_Click(object sender, EventArgs e)
{
bitmap = new Bitmap(300, 300);
g = Graphics.FromImage(bitmap);
this.pictureBox1.Image = bitmap;
}