如何将.tga图像转换为.png [英] How do I convert .tga images to .png

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

问题描述

我试图在c#中创建一个.tga图像转换器,我收到此消息:

System.OutOfMemoryException:'内存不足。'



我尝试过:



System.Drawing.Image image = System.Drawing.Image.FromFile(@ C:thefiles / thing.tga);

image.Save(@C:\ Users \ Me\Desktop\imagetest.png,System.Drawing.Imaging.ImageFormat。 Png);

解决方案

我不认为Targa图像是本机支持的。您可以查看 .NET Targa Image Reader [ ^ ]用于解决问题的阅读部分。

只是为了完整。



异常类型/错误消息具有误导性但记录在案:

备注



托管GDI +内置编码器和支持以下文件类型的解码器:

BMP

GIF

JPEG

PNG

TIFF



文件保持锁定状态直到图像被释放。



如果文件没有有效的图像格式或者GDI +不支持文件的像素格式,则此方法抛出OutOfMemoryException例外。

因此TGA图像本身不受支持,需要通过自己的代码或使用库来处理。


i im trying to make a .tga image converter in c# and i get this message:
System.OutOfMemoryException: 'Out of memory.'

What I have tried:

System.Drawing.Image image = System.Drawing.Image.FromFile(@"C:thefiles/thing.tga");
image.Save(@"C:\Users\Me\Desktop\imagetest.png",System.Drawing.Imaging.ImageFormat.Png);

解决方案

I don't think Targa images are natively supported. You may want to check out .NET Targa Image Reader[^] for the reading part of the problem.


Just for completeness.

The exception type / error message is misleading but documented:

Remarks

Managed GDI+ has built-in encoders and decoders that support the following file types:
BMP
GIF
JPEG
PNG
TIFF

The file remains locked until the Image is disposed.

If the file does not have a valid image format or if GDI+ does not support the pixel format of the file, this method throws an OutOfMemoryException exception.

So TGA images are not natively supported and require to be handled by own code or using a library.


这篇关于如何将.tga图像转换为.png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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