728x90
728x170
■ 이미지 파일을 WebP 이미지 파일로 저장하는 방법을 보여준다.
▶ Program.cs
using System.IO;
using ImageProcessor;
using ImageProcessor.Imaging.Formats;
using ImageProcessor.Plugins.WebP.Imaging.Formats;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
private static void Main()
{
string sourceFilePath = "source.png";
string targetFilePath = "target.webp";
SaveWebPImage(sourceFilePath, targetFilePath);
}
#endregion
#region WebP 이미지 저장하기 - SaveWebPImage(sourceFilePath, targetFilePath)
/// <summary>
/// WebP 이미지 저장하기
/// </summary>
/// <param name="sourceFilePath">소스 파일 경로</param>
/// <param name="targetFilePath">타겟 파일 경로</param>
private static void SaveWebPImage(string sourceFilePath, string targetFilePath)
{
byte[] sourceByteArray = File.ReadAllBytes(sourceFilePath);
ISupportedImageFormat format = new WebPFormat { Quality = 100 };
using(MemoryStream sourceStream = new MemoryStream(sourceByteArray))
{
using(FileStream targetStream = new FileStream(targetFilePath, FileMode.Create, FileAccess.ReadWrite))
{
using(ImageFactory imageFactory = new ImageFactory(preserveExifData : true))
{
imageFactory.Load(sourceStream).Format(format).Save(targetStream);
}
}
}
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] WIN32 API 함수 사용시 마지막 에러 메시지 구하기 (0) | 2021.05.26 |
---|---|
[C#/COMMON] UWP 앱 윈도우 최소화/복원하기 (0) | 2021.05.25 |
[C#/COMMON] 카카오 API를 사용해 키워드 장소 검색하기 (0) | 2021.05.23 |
[C#/COMMON] UWP 프로세스/윈도우 리스트 구하기 (0) | 2021.05.23 |
[C#/COMMON] ZipArchive 클래스 : ZIP 파일 생성하기/추출하기 (기능 개선) (0) | 2021.05.21 |
[C#/COMMON] Thread 클래스 : 특정 사용자 권한으로 스레드 실행하기 (0) | 2021.05.14 |
[C#/COMMON] 리소스 풀(Resource Pool) 사용하기 (0) | 2021.05.13 |
[C#/COMMON] Visual Studio 확장 개발하기 (0) | 2021.05.13 |
[C#/COMMON] Process 클래스 : UWP 프로세스 여부 구하기 (0) | 2021.05.13 |
[C#/COMMON] 스푸핑(spoofing) 기법을 사용해 시스템 권한으로 프로세스 실행하기 (0) | 2021.05.12 |