Пример #1
0
    public static bool AvoidAdaptSize = false; //Jpeg compression creates different images in TeamCity

    /// <param name="titleOrDescription">
    /// Replaces a placeholder-image with the provided image by comparing title/description
    ///
    /// Word Image -> Right Click -> Format Picture -> Alt Text -> Title
    /// </param>
    public static void ReplaceImage(this WordprocessingDocument doc, string titleOrDescription, Bitmap bitmap, string newImagePartId, bool adaptSize = false, ImagePartType imagePartType = ImagePartType.Png)
    {
        var blip = doc.FindBlip(titleOrDescription);

        if (adaptSize && AvoidAdaptSize == false)
        {
            var size = doc.GetBlipBitmapSize(blip);
            bitmap = ImageResizer.Resize(bitmap, size.Width, size.Height);
        }

        doc.ReplaceBlipContent(blip, bitmap, newImagePartId, imagePartType);
    }