Kode kanggo ngompres TIFF ing C#

Pustaka .NET kinerja dhuwur kanggo ngoptimalake isi lan ukuran TIFF njaga kualitas asli lan data dasar

Iki minangka solusi profesional kanggo ngompres TIFF nggunakake C#, F#, VB.NET. Gunakake API optimasi TIFF kanggo ngembangake piranti lunak tingkat dhuwur, platform-independen kanggo platform .NET lan .NET Core. Coba online gratis!

Ndeleng potongan kode

Kompres file TIFF ing C#

Nggawe file TIFF gedhe luwih cilik tanpa mundhut kualitas. Mbusak data sing ora perlu lan ora digunakake. Nyilikake ukuran file TIFF ing kode. Pustaka C# nyedhiyakake pangembang API terpadu kanggo ngoptimalake isi TIFF.

Ngurangi ukuran file TIFF nggunakake C#

Perpustakaan C# minangka solusi mandiri lan ora mbutuhake piranti lunak pihak katelu sing diinstal.

Kompresi lossless lan optimasi isi jero digawe gampang karo 'Aspose.Words for .NET'. Conto ing ngisor iki nuduhake carane ngoptimalake isi file TIFF ing C#:

Conto kode ing C# kanggo ngompres TIFF file
Unggah file sing pengin dioptimalake / kompres
Kode roto
Pilih format target saka dhaptar
dotnet add package Aspose.Words
Nyalin
using Aspose.Words;

var doc = new Document();
var builder = new DocumentBuilder(doc);

var shape = builder.InsertImage("Input.tiff");

var saveOptions = new ImageSaveOptions(SaveFormat.Tiff)
{
  TiffCompression = TiffCompression.Lzw
};

shape.GetShapeRenderer().Save("Output.tiff", saveOptions);
using Aspose.Words; var doc = new Document("Input.tiff"); doc.Cleanup(); var nodes = doc.GetChildNodes(NodeType.Shape, true); foreach (Shape shape in nodes) { if (shape.IsImage) { // Iku nganti pangembang kanggo milih perpustakaan kanggo komprèsi gambar. using var image = Image.FromStream(shape.ImageData.ToStream()); // ... // Compress gambar lan nyetel maneh menyang wangun. shape.ImageData.SetImage("yourCompressedImage"); } } var saveOptions = new PdfSaveOptions { CacheBackgroundGraphics = true }; doc.Save("Output.tiff", saveOptions); using Aspose.Words; var doc = new Document("Input.tiff"); doc.Cleanup(); var nodes = doc.GetChildNodes(NodeType.Shape, true); foreach (Shape shape in nodes) { if (shape.IsImage) { // Iku nganti pangembang kanggo milih perpustakaan kanggo komprèsi gambar. using var image = Image.Fromstream(shape.ImageData.ToStream()); // ... // Compress gambar lan nyetel maneh menyang wangun. shape.ImageData.SetImage("yourCompressedImage"); } } doc.Save("Output.tiff"); using Aspose.Words; var doc = new Document("Input.tiff"); doc.Cleanup(); var nodes = doc.GetChildNodes(NodeType.Shape, true); foreach (Shape shape in nodes) { if (shape.IsImage) { // Iku nganti pangembang kanggo milih perpustakaan kanggo komprèsi gambar. using var image = Image.FromStream(shape.ImageData.ToStream()); // ... // Compress gambar lan nyetel maneh menyang wangun. shape.ImageData.SetImage("yourCompressedImage"); } } var saveOptions = new OoxmlSaveOptions { CompressionLevel = CompressionLevel.Maximum }; doc.Save("Output.tiff", saveOptions); using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var shape = builder.InsertImage("Input.tiff"); var saveOptions = new ImageSaveOptions(SaveFormat.Tiff) { TiffCompression = TiffCompression.Lzw }; shape.GetShapeRenderer().Save("Output.tiff", saveOptions); using Aspose.Words; using Aspose.Words.Pdf2Word.FixedFormats; using var pdfStream = File.OpenRead("Input.tiff"); var renderer = new PdfFixedRenderer(); var pdfReadOptions = new PdfFixedOptions { ImageFormat = FixedImageFormat.Jpeg, JpegQuality = 50 }; const double maxPageDimension = 1584; var pagesStream = renderer.SavePdfAsImages(pdfStream, pdfReadOptions); var builder = new DocumentBuilder(); for (var i = 0; i < pagesStream.Count; ++i) { // Setel ukuran kaca maksimal kanggo ngindhari skala gambar kaca saiki. var pageSetup = builder.PageSetup; SetPageSize(pageSetup, maxPageDimension, maxPageDimension); var pageImage = builder.InsertImage(pagesStream[i]); SetPageSize(pageSetup, pageImage.Width, pageImage.Height); pageSetup.TopMargin = 0; pageSetup.LeftMargin = 0; pageSetup.BottomMargin = 0; pageSetup.RightMargin = 0; if (i != pagesStream.Count - 1) builder.InsertBreak(BreakType.SectionBreakNewPage); } var saveOptions = new PdfSaveOptions { CacheBackgroundGraphics = true }; builder.Document.Save("Output.tiff", saveOptions); private void SetPageSize(PageSetup pageSetup, double width, double height) { pageSetup.PageWidth = width; pageSetup.PageHeight = height; }
Kode roto

Cara ngompres TIFF Ing C#

  1. Pasang Aspose.Words for .NET.
  2. Tambah referensi perpustakaan (ngimpor perpustakaan) menyang proyek C# sampeyan.
  3. Bukak TIFF berkas sumber ing C#.
  4. Kompres TIFF tanpa kelangan kualitas.
  5. Telpon metode Document.Cleanup(). Kode asil bisa beda-beda gumantung saka format file output.
  6. Entuk asil sing dikompres minangka TIFF file.

Pustaka C# kanggo ngoptimalake lan ngompres TIFF file

Ana telung pilihan alternatif kanggo nginstal "Aspose.Words kanggo .NET" sistem sampeyan. Pilih salah siji sing cocog karo kabutuhan sampeyan lan tindakake pandhuan langkah demi langkah:

Syarat Sistem

Produk kita kanthi lintas-platform lan ndhukung kabeh implementasi .NET utama:

  • .NET ≥ 5.0
  • .NET Core ≥ 2.0
  • .NET Standard ≥ 2.0
  • .NET Framework ≥ 3.5
  • MonoMac
  • MonoAndroid
  • Xamarin

Nganti kode .NET ora gumantung ing hardware utawa sistem operasi sing ndasari, nanging mung ing Mesin Virtual, sampeyan bebas ngembangake piranti lunak apa wae kanggo Windows, macOS, Android, iOS lan Linux. Priksa manawa sampeyan wis nginstal versi .NET Framework, .NET Core, Windows Azure, Mono utawa Xamarin sing cocog.

Disaranake nggunakake Microsoft Visual Studio, Xamarin, lan lingkungan pangembangan terintegrasi MonoDevelop kanggo nggawe aplikasi C#, F#, VB.NET.

Kanggo rincian liyane, waca Dokumentasi Produk.

Optimasi format file liyane sing didhukung

Sampeyan bisa ngoptimalake file ing akeh format file liyane:

5%

Langganan kanggo Aspose Update Product

Entuk buletin saben wulan lan tawaran langsung dikirim menyang kothak layang.

© Aspose Pty Ltd 2001-2024. Kabeh hak dilindhungi undhang-undhang.