1、通过.net自带类库实现,代码如下:
Image Img
=
Image.FromFile(
@"
E:\AAA.bmp
"
);
System.Drawing.Imaging.PixelFormat _PF
=
Img.PixelFormat;
![None.gif](/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**/
/* 备注:如果Img图像是索引像素格式,下面的方法将引发异常
* 如:
* PixelFormat.Format1bppIndexed
* PixelFormat.Format4bppIndexed
* PixelFormat.Format8bppIndexed
* 另外,下列格式也会引发异常
* PixelFormat.Undefined
* PixelFormat.DontCare
* PixelFormat.Format16bppArgb1555
* PixelFormat.Format16bppGrayScale
*/
Graphics Gra
=
System.Drawing.Graphics.FromImage(Img);
![None.gif](/Images/OutliningIndicators/None.gif)
Font _F
=
new
Font(
"
宋体
"
,
24
);
SolidBrush _B
=
new
SolidBrush(Color.Black);
![None.gif](/Images/OutliningIndicators/None.gif)
Pen _P
=
new
Pen(_B,
10
);
![None.gif](/Images/OutliningIndicators/None.gif)
Gra.DrawString(
"
博客园
"
,_F,_B,
10
,
10
);
Gra.DrawLine(_P,
1
,
1
,
100
,
100
);
![None.gif](/Images/OutliningIndicators/None.gif)
Gra.Flush();
![None.gif](/Images/OutliningIndicators/None.gif)
Gra.Dispose();
![None.gif](/Images/OutliningIndicators/None.gif)
Img.Save(
@"
E:\AAA2.bmp
"
);
2、通过Office 2003自带的Microsoft.Office.Document.Imaging 11.0 Type Library来进行操作,文件位置:c:\program files\common files\microsoft shared\modi\mdivwctl.dll
代码如下:
using
System;
using
MODI;
namespace
AddImg
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
class TestAddImg
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
[STAThread]
static void Main(string[] args)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MODI.Document Doc = new Document();
Doc.Create(@"D:\myTiff.TIF");
Doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH,false,false);
Doc.Save();
MODI.Image img = (MODI.Image)Doc.Images[0];
Console.WriteLine(img.Layout.Text);
Console.ReadLine();
}
}
}
PS : 这两种方式都要求User必须对该图片要有操作权限,否则会报Access denied.