在C#中保存图像..请帮助 [英] Saving an Image in C# ..Please Help

查看:65
本文介绍了在C#中保存图像..请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家。

我在c#中创建了一个简单的Windows应用程序,用户可以将图像转换为jpg,png和bmp文件。

这样做效果很好,但我的问题是,当我按下保存按钮时,打开保存对话框并要求用户键入文件的名称,因为他们希望将其保存为...而不是用户键入全名..eg button.png是否有一种方法可以对此进行编码,以便用户只能输入按钮,文件会自动保存为button.png,而无需用户实际输入.PNG ..我希望这很有道理。

代码:

i有3个单选按钮供用户选择

单选按钮1 = jpeg

单选按钮2 = png

收音机bbutton 3 = bmp



Hi Guys.
I have created a simple windows app in c# that enables users to convert images to jpg, png and bmp files.
This works well but my issue is that when ever i press the the "save button" the opens the save dialogue and asks the user to type in the name of the file as they would like it to be saved as ... but instead of the user to type the whole name ..e.g. "button.png" is there a way that i could code this so that the user could only type in "button" and the file automatically saves as "button.png" without the user actually typing in the the .PNG .. I hope this makes sense.
CODE:
i have 3 radio buttons to be selected by the user
radio button 1 = jpeg
radio button 2 = png
radio bbutton 3 = bmp

private void button2_Click(object sender, EventArgs e)
{
    DialogResult saveimage = saveFileDialog1.ShowDialog();

    if (saveimage == DialogResult.OK)
    {

        if (radioButton1.Checked)
        {

            file.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
        }

        if (radioButton2.Checked)
        {

            file.Save(saveFileDialog1.FileName , ImageFormat.Png);

        }



        if (radioButton3.Checked)
        {

            file.Save(saveFileDialog1.FileName, ImageFormat.Bmp);
        }

    }

推荐答案

如果您预先选择要保存的图像类型,获取文件保存对话框以获得图像类型的下拉列表,或者如果您只有一个针对每种图像类型的按钮并让他们键入文件名,您可以从保存对话框中获取带扩展名的路径,或者自己附加。
If you pre select the type of image to save, and get the file save dialog to have a drop list of image types, or if you just have a button that is for each image type and let them type in the file name, you can either get the path with the extension from the save dialog, or append it yourself.


您好b $ b

查看
Hi
Check out the
SaveFileDialog.AddExtension

属性。有关详细信息,请参阅 http://msdn.microsoft.com/en -us / library / system.windows.forms.filedialog.addextension.aspx [ ^ ]


$ b $bUroš

property. For more details see the http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.addextension.aspx[^]

Uroš


这篇关于在C#中保存图像..请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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