将面板另存为图像 [英] Saving Panel as an Image

查看:84
本文介绍了将面板另存为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做这个绘画应用程序。很简单。它由一个面板组成,我将在该面板上进行绘制,然后最后将其另存为JPG或BMP或PNG文件。

I'm doing this paint application. It's kind of simple. It consist of a panel where I will draw on and then finally I will save as JPG or BMP or PNG file.

我的应用程序运行正常,但是我面临的问题是,当我保存输出时,不是面板上显示的黑色图像,而是黑色图像。

My application work perfectly but the problem I'm facing is that when I'm saving the output is not what drawn on the panel its black Image nothing just black.

我所有的工作都保存为

Thepic = new Bitmap(panel1.ClientRectangle.Width, this.ClientRectangle.Height);

然后在鼠标上(向下,向上的东西)

and on the mouse (down,up thing) I have

snapshot = (Bitmap)tempDraw.Clone();

它可以正常保存工作,但结果又是黑色的,而不是面板包含的内容。

and it saved the work normally but again the rsult is black Image not what the panel contain.

推荐答案

我认为问题可能在于您使用的是克隆方法。

I think the problem may be that you're using the "Clone" method.

尝试 DrawToBitmap -过去对我有用。

Try "DrawToBitmap" - that's worked for me in the past.

下面是一个示例,该示例保存了名为 plotPrinter的控件中的位图:

Here's a sample that saves a bitmap from a control called "plotPrinter":

        int width = plotPrinter.Size.Width;
        int height = plotPrinter.Size.Height;

        Bitmap bm = new Bitmap(width, height);
        plotPrinter.DrawToBitmap(bm, new Rectangle(0, 0, width, height));

        bm.Save(@"D:\TestDrawToBitmap.bmp", ImageFormat.Bmp);




        Be aware of saving directly to the C directly as this is not 
        permitted with newer versions of window, try using SaveFileDialog.




    SaveFileDialog sf = new SaveFileDialog();
    sf.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif|JPEG Image (.jpeg)|*.jpeg|Png Image (.png)|*.png|Tiff Image (.tiff)|*.tiff|Wmf Image (.wmf)|*.wmf";
    sf.ShowDialog();
    var path = sf.FileName; 

这篇关于将面板另存为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆