728x90
- 우선 visual studio 상단 메뉴바에서 '도구' -> 'NuGet 패키지 관리자' -> '패키지 관리자 콘솔' 을 클릭해줍니다.
- 콘솔창에 'Install-Package Aspose.Imaging' 해줍니다.
- 다음과 같은 코드를 작성합니다.
using Aspose.Imaging;
using Aspose.Imaging.Exif;
using Aspose.Imaging.Exif.Enums;
using Aspose.Imaging.FileFormats.Bmp;
using Aspose.Imaging.FileFormats.Dicom;
using Aspose.Imaging.FileFormats.Djvu;
using Aspose.Imaging.FileFormats.Emf;
using Aspose.Imaging.FileFormats.Eps;
using Aspose.Imaging.FileFormats.Eps.Consts;
using Aspose.Imaging.FileFormats.Gif;
using Aspose.Imaging.FileFormats.Gif.Blocks;
using Aspose.Imaging.FileFormats.Jpeg;
using Aspose.Imaging.FileFormats.Jpeg2000;
using Aspose.Imaging.FileFormats.Pdf;
using Aspose.Imaging.FileFormats.Png;
using Aspose.Imaging.FileFormats.Psd;
using Aspose.Imaging.FileFormats.Svg;
using Aspose.Imaging.FileFormats.Tga;
using Aspose.Imaging.FileFormats.Tiff.Enums;
using Aspose.Imaging.ImageFilters.FilterOptions;
using Aspose.Imaging.ImageOptions;
using Aspose.Imaging.Sources;
using Aspose.Imaging.Xmp;
using Aspose.Imaging.Xmp.Schemas.Dicom;
using Aspose.Imaging.Xmp.Types.Complex.Font;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace TiffToJpg
{
internal class Class1
{
static void Main(string[] args)
{
string rootPath = "D:\\heeyeon\\wallcrackdata\\images\\건물 균열 탐지 이미지\\Training\\콘크리트\\[원천]콘크리트_콘크리트균열_원천_14";
string savePath = "D:\\heeyeon\\wallcrackdata\\images\\ConcreteCrack\\ConcreteCrack14_JPG\\";
string[] files = Directory.GetFiles(rootPath, "*", SearchOption.AllDirectories);
//folder_path (ex)-> c:\user\source\repo\project_name
if (Directory.Exists(savePath) == false)
{
Directory.CreateDirectory(savePath);
}
foreach (string file in files)
{
if (file.EndsWith(".tiff")) //json 파일인지 검사
{
try
{
// Image.Load 메서드를 호출하여 TIFF 이미지 파일을 로드하고 이를 TiffImage 클래스의 이미지에 할당합니다.
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Image.Load(file))
{
// TIFF 이미지의 프레임을 반복합니다.
foreach (Aspose.Imaging.FileFormats.Tiff.TiffFrame tiffFrame in tiffImage.Frames)
{
// JpegOptions 클래스의 인스턴스를 초기화합니다.
Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
// 이미지 저장 옵션의 해상도를 설정하려면 ResolutionSetting 클래스의 개체를 만듭니다.
saveOptions.ResolutionSettings = new ResolutionSetting(tiffFrame.HorizontalResolution, tiffFrame.VerticalResolution);
if (tiffFrame.FrameOptions != null)
{
// ResolutionUnit 속성 값을 설정하여 해상도 단위를 명시적으로 설정합니다.
switch (tiffFrame.FrameOptions.ResolutionUnit)
{
case Aspose.Imaging.FileFormats.Tiff.Enums.TiffResolutionUnits.None:
saveOptions.ResolutionUnit = ResolutionUnit.None;
break;
case Aspose.Imaging.FileFormats.Tiff.Enums.TiffResolutionUnits.Inch:
saveOptions.ResolutionUnit = ResolutionUnit.Inch;
break;
case Aspose.Imaging.FileFormats.Tiff.Enums.TiffResolutionUnits.Centimeter:
saveOptions.ResolutionUnit = ResolutionUnit.Cm;
break;
default:
throw new System.NotSupportedException();
}
}
// 저장 메소드를 호출하여 TIFF 이미지를 JPG 이미지 형식으로 저장하십시오.
Console.WriteLine(Path.GetFileNameWithoutExtension(file));
tiffFrame.Save(savePath + Path.GetFileNameWithoutExtension(file) + ".jpg", saveOptions);
}
}
}
catch (Exception e)
{
File.Delete(file);
Console.WriteLine(e.Message);
}
}
}
}
}
}
- rootPath: tiff가 담긴 폴더의 경로입니다.
- savePath: jpg로 바뀐 파일들이 저장될 경로입니다.
728x90
'c#' 카테고리의 다른 글
[c#] 디렉터리 하위까지 검사해서 특정 확장자를 가진 파일만 삭제하기 (1) | 2024.01.08 |
---|---|
[c#] Dictionary 의 value 값이 Dictionary 일 경우 데이터 추가하기 (0) | 2023.11.28 |
[c#] 문자열이 숫자인지 확인 & 문자열 자르기 (0) | 2023.04.06 |
[c#] ftp에서 불러온 파일을 저장할 때, 같은 이름의 파일이 있을 경우 넘버링(숫자) 해주기 (0) | 2023.03.29 |
[c#] FTP에서 매개변수 "logName"을 파일 명으로 가진 파일을 다운로드하는 창 띄우기 (0) | 2023.03.27 |