45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public class ImageConverter_Draw : MonoBehaviour
|
|
{
|
|
// PNG转TIFF
|
|
public static void PngToTiff(string pngPath, string tiffPath)
|
|
{
|
|
using (Image pngImage = Image.FromFile(pngPath))
|
|
{
|
|
pngImage.Save(tiffPath, ImageFormat.Tiff);
|
|
}
|
|
}
|
|
|
|
// TIFF转PNG
|
|
public static void TiffToPng(string tiffPath, string pngPath)
|
|
{
|
|
using (Image tiffImage = Image.FromFile(tiffPath))
|
|
{
|
|
tiffImage.Save(pngPath, ImageFormat.Png);
|
|
}
|
|
}
|
|
|
|
[SerializeField]string pngPath;
|
|
[SerializeField]string tiffPath;
|
|
[SerializeField]string outputPngPath;
|
|
|
|
// 示例用法
|
|
void Start()
|
|
{
|
|
// pngPath = Application.dataPath + "/test.png";
|
|
// tiffPath = Application.dataPath + "/converted.tif";
|
|
// outputPngPath = Application.dataPath + "/converted.png";
|
|
|
|
// PNG -> TIFF
|
|
PngToTiff(pngPath, tiffPath);
|
|
Debug.Log("PNG to TIFF conversion done!");
|
|
|
|
// TIFF -> PNG
|
|
TiffToPng(tiffPath, outputPngPath);
|
|
Debug.Log("TIFF to PNG conversion done!");
|
|
}
|
|
} |