翻譯|使用教程|編輯:李顯亮|2020-01-02 09:34:32.477|閱讀 472 次
概述:本文我們將進(jìn)入關(guān)于“圖像處理”的介紹,在Aspose.Words中學(xué)會(huì)如何鎖定圖像的寬高比并截取圖像。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.Words For .Net是一種高級(jí)Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無(wú)需在跨平臺(tái)應(yīng)用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
接下來(lái)我們將進(jìn)入關(guān)于“圖像處理”的介紹,在Aspose.Words中學(xué)會(huì)如何鎖定圖像的寬高比并截取圖像。
>>Aspose.Words for .NET更新至最新版v19.12,支持轉(zhuǎn)換為PDF 1.7標(biāo)準(zhǔn),點(diǎn)擊下載體驗(yàn)
獲取點(diǎn)的實(shí)際形狀邊界
如果要在頁(yè)面上呈現(xiàn)形狀的實(shí)際邊界框,可以使用NodeRendererBase.BoundsInPoints屬性來(lái)實(shí)現(xiàn)。下面的代碼示例演示如何使用此屬性。
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); var shape = builder.InsertImage(dataDir + "Test.png"); shape.AspectRatioLocked = false; dataDir = dataDir + "Shape_AspectRatioLocked_out.doc"; // Save the document to disk. doc.Save(dataDir);
裁剪圖像
圖像裁剪通常是指去除圖像不需要的外部部分以幫助改善取景。它還用于 去除圖像的某些 部分,以增加對(duì)特定區(qū)域的聚焦。可以使用Aspose.Words API來(lái)實(shí)現(xiàn),如下面的示例所示。
string dataDir = RunExamples.GetDataDir_WorkingWithImages(); string inputPath = dataDir + "ch63_Fig0013.jpg"; string outputPath = dataDir + "cropped-1.jpg"; CropImage(inputPath,outputPath, 124, 90, 570, 571);
public static void CropImage(string inPath, string outPath, int left, int top,int width, int height) { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Image img = Image.FromFile(inPath); int effectiveWidth = img.Width - width; int effectiveHeight = img.Height - height; Shape croppedImage = builder.InsertImage(img, ConvertUtil.PixelToPoint(img.Width - effectiveWidth), ConvertUtil.PixelToPoint(img.Height - effectiveHeight)); double widthRatio = croppedImage.Width / ConvertUtil.PixelToPoint(img.Width); double heightRatio = croppedImage.Height / ConvertUtil.PixelToPoint(img.Height); if (widthRatio< 1) croppedImage.ImageData.CropRight = 1 - widthRatio; if (heightRatio< 1) croppedImage.ImageData.CropBottom = 1 - heightRatio; float leftToWidth = (float)left / img.Width; float topToHeight = (float)top / img.Height; croppedImage.ImageData.CropLeft = leftToWidth; croppedImage.ImageData.CropRight = croppedImage.ImageData.CropRight - leftToWidth; croppedImage.ImageData.CropTop = topToHeight; croppedImage.ImageData.CropBottom = croppedImage.ImageData.CropBottom - topToHeight; croppedImage.GetShapeRenderer().Save(outPath, new ImageSaveOptions(SaveFormat.Jpeg)); }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn