Iki minangka solusi profesional kanggo ngompres JPG nggunakake C#, F#, VB.NET. Gunakake API optimasi JPG kanggo ngembangake piranti lunak tingkat dhuwur, platform-independen kanggo platform .NET lan .NET Core. Coba online gratis!
Nggawe JPG file gedhe luwih cilik tanpa mundhut kualitas. Mbusak data sing ora perlu lan ora digunakake. Nyilikake ukuran JPG file ing kode. Pustaka C# nyedhiyakake pangembang API terpadu kanggo ngoptimalake isi JPG.
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 JPG file ing C#:
dotnet add package Aspose.Words
Nyalin
using Aspose.Words;
var doc = new Document();
var builder = new DocumentBuilder(doc);
var shape = builder.InsertImage("Input.jpg");
var saveOptions = new ImageSaveOptions(SaveFormat.Jpeg)
{
JpegQuality = 50
};
shape.GetShapeRenderer().Save("Output.jpg", saveOptions);
using Aspose.Words;
var doc = new Document("Input.jpg");
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.jpg", saveOptions);
using Aspose.Words;
var doc = new Document("Input.jpg");
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.jpg");
using Aspose.Words;
var doc = new Document("Input.jpg");
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.jpg", saveOptions);
using Aspose.Words;
var doc = new Document();
var builder = new DocumentBuilder(doc);
var shape = builder.InsertImage("Input.jpg");
var saveOptions = new ImageSaveOptions(SaveFormat.Jpeg)
{
JpegQuality = 50
};
shape.GetShapeRenderer().Save("Output.jpg", saveOptions);
using Aspose.Words;
using Aspose.Words.Pdf2Word.FixedFormats;
using var pdfStream = File.OpenRead("Input.jpg");
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.jpg", saveOptions);
private void SetPageSize(PageSetup pageSetup, double width, double height)
{
pageSetup.PageWidth = width;
pageSetup.PageHeight = height;
}
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:
Produk kita kanthi lintas-platform lan ndhukung kabeh implementasi .NET utama:
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.
Sampeyan bisa ngoptimalake file ing akeh format file liyane: