我是靠谱客的博主 俊秀金鱼,最近开发中收集的这篇文章主要介绍Aword无题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 /// <summary>
/// 书签处插入处理后的图片
/// </summary>
/// <param name="Doc"></param>
/// <param name="Img"></param>
/// <param name="markName"></param>
/// <param name="ShengxiaNn">剩下大小</param>
/// <returns></returns>
public static bool InsertCutImage(Document Doc, Image Img, string markName,int ShengxiaNn)
{
if (Doc.Range.Bookmarks[markName] != null && Img != null)
{
try
{
Image ImageZhuanhuan;
ImageZhuanhuan = new Bitmap(Img);
Img.Dispose();
DocumentBuilder builder = new DocumentBuilder(Doc);
builder.MoveToBookmark(markName);
double displayWidth = 600;//显示宽度
double displayHeight = 610;//显示高度度
double zoomRate = 0;
if ((double)ImageZhuanhuan.Width / (double)ImageZhuanhuan.Height < displayWidth / displayHeight)
{
zoomRate = displayHeight / ImageZhuanhuan.Height;//缩放比例
displayWidth = ImageZhuanhuan.Width * zoomRate;//显示高度 
}
else
{
zoomRate = displayWidth / ImageZhuanhuan.Width;//缩放比例
displayHeight = ImageZhuanhuan.Height * zoomRate;//显示高度 
}
int FirstImageHight = (int)Math.Floor( (double)ShengxiaNn/zoomRate);//第一张图片的大小
Image ImageFirst = null;
Image ImageSecond= null;
if (FirstImageHight >= ShengxiaNn)//如果大于则需要分解
{
ImageFirst = ImageZhuanhuan;
}
else
{
int FirstHeight = FirstImageHight;//第一个图片的高度
int SecondHeight = ImageZhuanhuan.Height - FirstHeight;//第二个图片的高度
ImageFirst = Common.ImageHelper.CaptureImage(ImageZhuanhuan,0,0,ImageZhuanhuan.Width,FirstHeight);
ImageSecond = Common.ImageHelper.CaptureImage(ImageZhuanhuan, 0, FirstImageHight, ImageZhuanhuan.Width, SecondHeight);
}
if (ImageFirst!=null)
{
Shape shape = builder.InsertImage(ImageFirst);
shape.Width = displayWidth;//ImageZhuanhuan.Width; 
shape.Height = displayHeight;//ImageZhuanhuan.Height;
基本是以上下高度为准
shape.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
//shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;//图片居中对齐
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
shape.WrapType = WrapType.Square;
if (ImageSecond != null)
{
//Run run = Doc.GetChildNodes(NodeType.Run, true)[Doc.GetChildNodes(NodeType.Run, true).Count - 1] as Run;
Run run = Doc.GetChildNodes(NodeType.Run, true)[Doc.GetChildNodes(NodeType.Run, true).Count + 1] as Run;
builder.MoveTo(run);
Shape shapeSec = builder.InsertImage(ImageSecond);
shapeSec.Width = displayWidth;//ImageZhuanhuan.Width; 
shapeSec.Height = displayHeight;//ImageZhuanhuan.Height;
基本是以上下高度为准
shapeSec.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
//shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;//图片居中对齐
shapeSec.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
shapeSec.WrapType = WrapType.Square;
}
}
//if (ImageSecond != null)
//{
//
Shape shape = builder.InsertImage(ImageSecond);
//
shape.Width = displayWidth;//ImageZhuanhuan.Width; 
//
shape.Height = displayHeight;//ImageZhuanhuan.Height;
基本是以上下高度为准
//
shape.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
//
//shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;//图片居中对齐
//
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
//
shape.WrapType = WrapType.Square;
//}

return true;
}
catch (Exception ex)
{
return false;
}
}
else
{
return false;
}
}

最后

以上就是俊秀金鱼为你收集整理的Aword无题的全部内容,希望文章能够帮你解决Aword无题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(35)

评论列表共有 0 条评论

立即
投稿
返回
顶部