How to add image in Aspose.Words and set it’s opacity? Is there is any property or something?
For example, the following code of Aspose.Imaging for .NET API creates a blank canvas of type PNG with transparency and draws another image over it while specifying the desired opacity (ColorMatrix.Matrix33). Please note, 0.3f means 30% so you may set it to any desired value. Moreover, you may change the opacity for every next image if you set this property in a loop.
using (PngImage pngImage = new PngImage(1500, 1500, PngColorType.TruecolorWithAlpha))
{
ColorMatrix cmxPic = new ColorMatrix();
cmxPic.Matrix33 = 0.3f;
ImageAttributes iaPic = new ImageAttributes();
iaPic.SetColorMatrix(cmxPic, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
using (Image loaded = Image.Load(“d:/ temp / logo.png”))
{
Graphics gr = new Graphics(pngImage);
gr.DrawImage(loaded, loaded.Bounds, GraphicsUnit.Pixel, iaPic);
}
pngImage.Save(“D:/ newPng.png”);
}
After that your Image is processed you will then be able to insert image inside Word document and set its different parameters:
Document doc = new Document("E:\\Temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
Shape shape = builder.InsertImage("E:\\Temp\\Aspose.Words.jpg");
shape.Fill.Opacity = 0.7;
shape.Stroke.On = true;
shape.Stroke.Color = doc.Theme.Colors.Accent1;
shape.Stroke.Weight = 5;
shape.Stroke.Opacity = 0.7;
doc.Save("E:\\Temp\\19.12.docx");
Hope, this helps in achieving what you are looking for.
Is there is any possible way to use only Aspose.Words for this task?
I am thying to add some images, but opacity don’t work. I don’t need to use any other products
We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-19658 . We will further look into the details of this problem and will keep you updated on the status of the linked issue. We apologize for your inconvenience.
The issues you have found earlier (filed as WORDSNET-19658) have been fixed in this Aspose.Words for .NET 21.10 update also available on NuGet.