c#变量ImageFormat格式 [英] c# variable ImageFormat format

查看:514
本文介绍了c#变量ImageFormat格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#
我希望能够以不同的格式保存图像,但我无法做到。



这不是'工作:





public void CutFromScreen(string cut_from,int x,int y,int w,int h,string save_to)< br $>
{



string test =Png;



//Skær ud efter mus

Bitmap image = new Bitmap(cut_from);

Bitmap image2 = image.Clone(new System.Drawing.Rectangle(x,y,w,h) ,image.PixelFormat);

image2.Save(save_to,ImageFormat。+ test);

image.Dispose();

image2.Dispose();

}

c# I would like to be able to save images in different formats, but I'm not able to do it.

This doesn't work:


public void CutFromScreen(string cut_from, int x, int y, int w, int h, string save_to)
{

string test = "Png";

//Skær ud efter mus
Bitmap image = new Bitmap(cut_from);
Bitmap image2 = image.Clone(new System.Drawing.Rectangle(x, y, w, h), image.PixelFormat);
image2.Save(save_to, ImageFormat.+test);
image.Dispose();
image2.Dispose();
}

推荐答案

它甚至不会编译,根本没有任何意义。可以是

It won't even compile and makes no sense at all. Can be
image2.Save(save_to, ImageFormat.Png);





https://msdn.microsoft.com/ en-us / library / system.drawing.image%28v = vs.110%29.aspx

https://msdn.microsoft.com/en-us/library/9t4syfhh%28v=vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageformat%28v=vs.110%29.aspx

https://msdn.microsoft.com/en-us /library/system.drawing.imaging.imageformat.png(v=vs.110).aspx



注意 ImageFormat.Png 本身不是一个字符串(即使你正确使用了字符串语法),它也是类型 ImageFormat (静态只读属性)。



不幸的是,你的问题清楚地表明你没有关于编程如何工作的线索,什么是源代码,编译,类型和实例,属性,所有这些基础知识。我的意思是,还没有。你可以学到这一切。在想象或其他任何先进或更高级的东西之前更好地学习它。







可变格式?没有什么可以阻止你做变量。在您的代码示例中,您使用字符串文本 test ,它只是正式变量,但实际上在初始化中使用立即常量。没什么区别。你可以有一个 ImageFormat 类型的方法参数,它将使该方法应用格式变量。你真正传递给它的,取决于输入的内容。通常,这是用户的选择,例如,通过一些选择的列表框。并且不存在将字符串存储在其中的偏好。为了便于理解,请查看我过去的答案:

combobox.selectedvalue在winform中显示{},

如何以两种形式复制列表框之间的所有项目

更新不同窗口上的列表视图

wpf无模式对话框和窗口,如何沟通

带有小数的排序列表框



-SA



https://msdn.microsoft.com/en-us/library/system.drawing.image%28v=vs.110%29.aspx,
https://msdn.microsoft.com/en-us/library/9t4syfhh%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageformat%28v=vs.110%29.aspx,
https://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageformat.png(v=vs.110).aspx.

Note that ImageFormat.Png itself is not a string (even if you used string syntax correctly), it is also of the type ImageFormat (static read-only property).

Unfortunately, your question clearly shows that you have no clue on how programming works in general, what is source code, compilation, types and instances, properties, all basics like that. I mean, not yet. You can learn all that. Better learn it all before getting to imagine or anything else as advanced or more advanced.



Variable format? Nothing prevents you from doing it variable. In your code sample, you use the string text, test which is only formally variable, but in fact uses immediate constant in initialization. It makes no difference. You could have a method argument of the type ImageFormat and it will make the method's application of the format variable. What you really pass to it, depends on what comes on input. Usually, this is a user's choice, say, via some list box with choice. And there is no preference in storing strings in it. For understanding, please see my past answers:
combobox.selectedvalue shows {} in winform,
How to copy all the items between listboxes in two forms,
Updating listviews on different windows,
wpf modeless dialog and windows, how to communicate,
Sorted listbox with fractional numbers.

—SA


这篇关于c#变量ImageFormat格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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