本文介绍了从PictureBox保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
这是我的代码....
在保存"按钮上,单击我要保存图像...".
现在我面临的问题是当我保存图像时它正在保存空白.
当我打开图像时,它显示为空白...
Hi friends,
This is my code....
On Save Button click i want to save the Image...
Now what problem im facing is when i save th image it is saving blank.
When i open the image it is showing blank...
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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
Pen mypen;
bool bmousedown = false;
Point prevpoint;
Graphics g;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
mypen = new System.Drawing.Pen(System.Drawing.Color.Black);
g = pictureBox1.CreateGraphics();
mypen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
mypen.Color = Color.Black;
mypen.Width = 1.0f;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
prevpoint = e.Location;
bmousedown = true;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
bmousedown = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (bmousedown)
{
Point thispoint = e.Location;
if (prevpoint.X == 0 && prevpoint.Y == 0)
{
prevpoint = thispoint;
return;
}
g.DrawLine(mypen, thispoint.X, thispoint.Y, prevpoint.X, prevpoint.Y);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
prevpoint = thispoint;
}
}
private void btnSave_Click(object sender, EventArgs e)
{
using (SaveFileDialog sfdlg = new SaveFileDialog())
{
sfdlg.Title="Save Dialog";
sfdlg.Filter="Bitmap Images (*.bmp)|*.bmp|All files(*.*)|*.*";
if(sfdlg.ShowDialog(this)==DialogResult.OK)
{
using (Bitmap bmp = new Bitmap(pictureBox1.Width,pictureBox1.Height))
{
pictureBox1.DrawToBitmap(bmp,new Rectangle(0,0,bmp.Width ,bmp.Height));
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image.Save("c://cc.Jpg");
bmp.Save(sfdlg.FileName);
MessageBox.Show("Saved Successfully.....");
}
}
}
}
}
}
推荐答案
这篇关于从PictureBox保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!