
Konversi gambar TIFF ke JPG dalam C#
Instalasi perpustakaan konversi TIFF ke JPG
Bagian ini akan mendemonstrasikan prosedur penginstalan perpustakaan .NET ini. Jadi, unduh DLL atau instal pustaka ini dengan menjalankan perintah berikut di manajer paket NuGet.
Install-Package Aspose.Imaging
Konversi gambar TIFF ke JPG dalam C#
Untuk mengimplementasikan konversi TIFF ke JPG, Anda dapat mengikuti langkah-langkah dan cuplikan kode yang disebutkan di bawah ini: Silakan ikuti langkah-langkah dan cuplikan kode yang disebutkan di bawah ini:
- Aktifkan metode Image.Load untuk memuat file gambar TIFF dan menetapkannya ke instance kelas TiffImage.
- Ulangi frame gambar TIFF.
- Inisialisasi instance dari kelas JpegOptions.
- Buat objek dari kelas ResolutionSetting untuk mengatur resolusi untuk opsi penyimpanan gambar.
- Atur unit resolusi secara eksplisit dengan mengatur nilai properti ResolutionUnit.
- Aktifkan metode save untuk menyimpan gambar TIFF ke format gambar JPG.
Salin & tempel kode berikut ke file utama Anda:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 System; using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; // Invoke the Image.Load method to load the TIFF image file and assign it to the image of the TiffImage class. using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Image.Load("sample.tiff")) { // Loop through the frames of the TIFF image. int i = 0; foreach (Aspose.Imaging.FileFormats.Tiff.TiffFrame tiffFrame in tiffImage.Frames) { // Initialize an instance of the JpegOptions class. Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions(); // Create an object of the ResolutionSetting class to set the resolution for image save options. saveOptions.ResolutionSettings = new ResolutionSetting(tiffFrame.HorizontalResolution, tiffFrame.VerticalResolution); if (tiffFrame.FrameOptions != null) { // Set the resolution unit explicitly by setting the value of the ResolutionUnit property. 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(); } } // Invoke the save method to save the TIFF image to the JPG image format. tiffFrame.Save( "tiff-to-jpg.jpg", saveOptions); } }
Dapatkan Lisensi Gratis
Anda dapat memanfaatkan lisensi sementara gratis untuk mencoba API tanpa batasan evaluasi.
Menyimpulkan
Ini membawa kita ke akhir posting blog ini. Saya harap Anda telah mempelajari cara mengonversi TIFF ke gambar JPG di C# secara terprogram. Ada banyak metode lain yang diekspos oleh library TIFF to JPG conversion ini. Selanjutnya, Anda dapat mengunjungi dokumentasi untuk mengetahui tentang fitur lainnya. Selain itu, kami menyarankan Anda untuk mengikuti [Panduan Memulai] kami18. Terakhir, conholdate.com sedang menulis posting blog baru. Jadi, harap tetap berhubungan untuk pembaruan rutin.
Berikan pertanyaan
Anda dapat memberi tahu kami tentang pertanyaan atau pertanyaan Anda di forum kami.
FAQ
Bagaimana cara mengonversi TIFF ke JPG di C#? Silakan ikuti link ini untuk mengetahui tentang konversi TIFF ke JPG di C#.