110,571
社区成员
发帖
与我相关
我的任务
分享
public Image CreateImage(int width,int height,int x,int y,int length,Color color)
{
//画图初始化
Image bMap = new Bitmap(width, height);
Graphics gph = Graphics.FromImage(bMap);
Brush brush = new SolidBrush(color);
setBrush(ref brush);
try
{
PointF cPt = new PointF(x, y);
gph.DrawLine(Pens.Blue, cPt.X, cPt.Y, cPt.X + length, cPt.Y);
}
catch (Exception ex)
{
}
return bMap;
}
public static void ImageToWord(Image image)
{
string fileName = "tmp.jpg";
image.Save(fileName);
FileInfo fi = new FileInfo(fileName);
try
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application oword = new Microsoft.Office.Interop.Word.Application();
Document doc = oword.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
oword.Selection.Font.Bold = 1;
oword.Selection.Font.Size = 12;
oword.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
oword.Visible = true;
object LinkToFile = false;
oword.Application.Selection.InlineShapes.AddPicture(fi.FullName, ref Nothing, ref Nothing, ref Nothing); //doc为活动文档的名称,即正在操作的文档
}
catch (Exception ex) { Log.WriteErLog(ex.Message); }
finally
{
System.Diagnostics.Process[] CurrentProcess = System.Diagnostics.Process.GetProcessesByName("WINWORD");
for (int i = 0; i < CurrentProcess.Length; i++)
{
if (CurrentProcess[i].MainWindowHandle.ToInt32() == 0)
{
try
{
CurrentProcess[i].Kill();
}
catch
{
}
}
}
}
}