1. 程式人生 > >影象處理控制元件Aspose.Imaging v19.6新版亮點示例詳解(2)

影象處理控制元件Aspose.Imaging v19.6新版亮點示例詳解(2)

Aspose.Imaging for .NET一種高階影象處理控制元件,允許開發人員建立,編輯,繪製或轉換影象。影象匯出和轉換是API核心功能之一,它允許在不安裝Photoshop應用程式或任何其他影象編輯器的情況下儲存為AdobePhotoshop®本機格式。

近期釋出了Aspose.Imaging for .NET v19.6,JPEG輸出中不再保留IMAGINGNET-3351 DPI屬性,下面我們一起來探索新版中的新增功能及其工作原理。>>歡迎下載Aspose.Imaging for .NET v19.6體驗

▲JPEG輸出中不保留IMAGINGNET-3351 DPI屬性

string dir = "c:\\aspose.work\\IMAGINGNET\\3351\\";
 
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Image.Load(dir + "source2.tif"))
{
    int i = 0;
    foreach (Aspose.Imaging.FileFormats.Tiff.TiffFrame tiffFrame in tiffImage.Frames)
    {
        Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
        saveOptions.ResolutionSettings = new ResolutionSetting(tiffFrame.HorizontalResolution, tiffFrame.VerticalResolution);
 
        if (tiffFrame.FrameOptions != null)
        {
            // Set the resolution unit explicitly.
            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();
            }
        }
 
        string fileName = "source2.tif.frame." + (i++) + "." + saveOptions.ResolutionUnit + ".jpg";
        tiffFrame.Save(dir + fileName, saveOptions);
    }
}

 

▲IMAGINGNET-3321載入PNG影象時佔用大量記憶體

using (Image image = Image.Load("halfGigImage.png")) {
    // todo something
}

 

▲IMAGINGNET-3287將WMF轉換為SVG時會新增邊距

string dir = "c:\\aspose.work\\IMAGINGNET\\3287\\";
string fileName = dir + "image2.wmf";
 
// Save WMF to SVG
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileName))
{
    // The customer uses EmfRasterizationOptions instead of WmfRasterizationOptions.
    // EmfRasterizationOptions works correctly in .NET as well.
    Aspose.Imaging.ImageOptions.WmfRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.WmfRasterizationOptions();
    rasterizationOptions.PageSize = image.Size;
 
    Aspose.Imaging.ImageOptions.SvgOptions saveOptions = new Aspose.Imaging.ImageOptions.SvgOptions();
    saveOptions.VectorRasterizationOptions = rasterizationOptions;
 
    image.Save(fileName + ".svg", saveOptions);
}                
 
// Save WMF to PNG
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileName))
{
    // The customer uses EmfRasterizationOptions instead of WmfRasterizationOptions.
    // EmfRasterizationOptions works correctly in .NET as well.
    Aspose.Imaging.ImageOptions.WmfRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.WmfRasterizationOptions();
    rasterizationOptions.PageSize = image.Size;
 
    Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
    saveOptions.VectorRasterizationOptions = rasterizationOptions;
 
    image.Save(fileName + ".png", saveOptions);
}

 

▲IMAGINGNET-3378在將WMF轉換為PNG時裁剪影象寬度和高度

public void WmfToJpg() 
{
    using (Image image = Image.Load("portrt.wmf")) {
        image.Save(
                    "portrt.jpg",
                    new JpegOptions()
                        {
                            VectorRasterizationOptions = new WmfRasterizationOptions
                                                             {
                                                                 BackgroundColor = Color.WhiteSmoke,
                                                                 PageWidth = image.Width,
                                                                 PageHeight = image.Height,
                                                             }
                        });
    }
}
 
public void WmfToPngWithBorders() 
{
    using (Image image = Image.Load("portrt.wmf")) {
        image.Save(
                    "portrt.png",
                    new PngOptions()
                        {
                            VectorRasterizationOptions = new WmfRasterizationOptions
                                                             {
                                                                 BackgroundColor = Color.WhiteSmoke,
                                                                 PageWidth = image.Width,
                                                                 PageHeight = image.Height,
                                                                 BorderX = 50,
                                                                 BorderY = 20
                                                             }
                        });
    }
}

 

▲IMAGINGNET-3336使用ODG檔案格式時,將在控制檯中列印文字

string fileName = "example.odg";
using (OdgImage image = (OdgImage)Image.Load(fileName))
{
}

 

▲IMAGINGNET-3421 GIF檔案未正確轉換為PDF

public void TestExportGifToPdf() 
{
    string[] fileNames = new [] {
        "czone.gif",
        "DTRA_LogoType.gif",
        "DTRA_Seal.gif",
        "Equip1.gif",
        "Equip2.gif",
        "Equip3.gif"
    };
    foreach (string fileName in fileNames) {
        using (Image image = Image.Load(fileName))
        {
            image.Save(fileName + ".pdf", new PdfOptions());
        }
    }
}

 

▲IMAGINGNET-3205 RotateFlip操作與PSD無法正常工作

// RotateFlip operation doesn't work as expected with PSD
            string sourceFile = "1.psd";
            string pngPath = "RotateFlipTest2617.png";
            string psdPath = "RotateFlipTest2617.psd";
 
            RotateFlipType flipType = RotateFlipType.Rotate270FlipXY;
            using (var im = (PsdImage)(Image.Load(sourceFile)))
            {
                im.RotateFlip(flipType);
                im.Save(pngPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                im.Save(psdPath);
            }

 

▲IMAGINGNET-3374將DJVU格式轉換為影象的問題

using (DjvuImage image = (DjvuImage)Imaging.Image.Load(@"input.djvu"))
{
PngOptions exportOptions = new PngOptions();
    for (int i = 0; i < image.Pages.Length; i++)
    {
        DjvuPage page = image.Pages[i];
        page.Save(@"page" + i + ".png", exportOptions);
    }
}

 

▲IMAGINGNET-3339 SvgRasterizationOptions大小設定不起作用

using (Image image = Image.Load("test.svg"))
{
    image.Save("test.svg_out.bmp",
        new BmpOptions()
        {
            VectorRasterizationOptions = new SvgRasterizationOptions()
            {
                PageWidth = 100,
                PageHeight = 200
            }
         });
}

-- 未完待