我不明白这个问题。因为这通常工作到现在。该方法是点击后的反应,用于将图像保存在称为画布的图片框上。我将图像加载到画布上,然后进行一些编辑。然后我想保存图像。如果我在加载图像之前单击 printScreenButton 它可以工作,但是当我加载图像时它会停止工作。问题可能出在哪里?
private void printScreenButton_Click(object sender, EventArgs e)
{
canvas.Image.Save("name.png", System.Drawing.Imaging.ImageFormat.Png);
}
编辑:
工作==创建名为name.png的
文件不起作用==未创建名为name.png的文件
绘制图像的代码 == 放入图片框
` private void drawTransformedBitmap(Matrix transformationMatrix)
{
Graphics g = Graphics.FromImage(canvasBitmapShow); //prepare graphics
if (antialiasing)
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
}
else
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
}
g.Clear(Color.White); //clear canvas
g.Transform.Reset(); //clear transformations
g.Transform = transformationMatrix; //set transformations from transformationMatrix
g.DrawImage(canvasBitmapTarget, 0, 0); //draw from Bitmap called canvasBitmapTarget
canvas.Invalidate(); //refresh canvas
}`
一开始的初始化:
canvasBitmapShow = new Bitmap(canvas.Width, canvas.Height);
canvasBitmapSource = new Bitmap(canvas.Width, canvas.Height);
canvasBitmapTarget = new Bitmap(canvas.Width, canvas.Height);
canvasBitmapBackup = new Bitmap(canvas.Width, canvas.Height);
canvas.Image = canvasBitmapShow; //set the Image