改变图像的扩展名 [英] change the extension of image

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

问题描述

您好...我想将磁盘中图片的扩展名更改为ico扩展名我的代码错误

Hello...i want to change the extension of images in the disk to the ico extension what''s the wrong of my code

string ic = "ico";
foreach (var fil in Directory.GetFiles(Server.MapPath("~/minimalcolors/"))) {
string ext = fil.Substring(fil.IndexOf("."));
ext.Replace(ext, ic);

推荐答案

对任何事情的更改扩展绝对没用。它与实际的文件格式无关。

实际上,没有扩展这样的东西。由于历史原因,文件名末尾的最后三个字符或末尾的。之后的所有字符都称为扩展名。在过时的FAT文件系统和MS-DOS中,所有文件名都是8个字符的名称和3个字符的扩展名。在较新的系统中,不再存在这样的东西,但最后的文件名的一部分(如上所述)用于识别文件类型。这并不意味着什么;只是Windows Shell试图查找Windows注册表以找到用于打开文件的默认应用程序。如果扩展名与其实际内容和格式不符,则无法读取文件。



-SA
It is absolutely useless to "change extensions" of anything. It has nothing to do with actual file format.
Actually, there is no such thing as "extension". By historical reasons, either last three characters at the end of the file name, or all characters after ''.'' at the end are called "extension". In obsolete FAT file system and MS-DOS, all file names were 8-character name and 3-character "extension". In newer systems, there are no such thing anymore, but a part of file name at the end (as I described above) is used to identify "file type". It does not mean much; it''s just that the Windows Shell tried to look up the Windows registry to find the "default application" used to open the file. It cannot help to read the file if the "extension" does not match its actual content and format.

—SA


您应该使用 Path.ChangeExtension 方法。 MSDN链接 [ ^ ]

You should use Path.ChangeExtension method. MSDN Link[^]
var result = Path.ChangeExtension(yourfile, ".jpg");



如果要实际更改扩展名,可以使用 File.Move 方法:


If you want to physically change the extension, you could use File.Move method:

File.Move(yourfile, Path.ChangeExtension(yourfile, ".jpg"));



祝你好运,

OI


Good luck,
OI


这篇关于改变图像的扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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