如何使用Aspose.Imaging为图片添加数字签名

作者:控件中国网   出处:控件中国网   2015-12-09 10:24:13   阅读:28

很多时候为了避免伪造和盗版需要为图片添加数字签名,Aspose.Imaging提供的API可以帮助开发人员快速实现该功能,这篇文章介绍的实现方法主要是通过Graphics类来把签名的图片绘制到目标图片上,具体可以参考下面的详细步奏。
 
1.首先创建一个Image类的实例,然后从本地加载图片
using (Image canvas = Image.Load("D:/sample.jpg"))
{
    using (Image signature = Image.Load("D:/signature.gif"))
    {
2.创建和初始化一个Graphic对象
Graphics graphics = new Graphics(canvas);
3.把签名的图片绘制到目标图片
graphics.DrawImage(signature, new Point(canvas.Height - signature.Height, canvas.Width - signature.Width)); 
4.保存签名好的图片
canvas.Save("D:/output.png", new PngOptions());
该事例的完整代码如下:
//Create an instance of Image and load the primary image
using (Image canvas = Image.Load("D:/sample.jpg"))
{
    //Create another instance of Image and load the secondary image containing the signature graphics
    using (Image signature = Image.Load("D:/signature.gif"))
    {
        //Create an instance of Graphics class and initialize it using the object of the primary image
        Graphics graphics = new Graphics(canvas);
        //Call the DrawImage method while passing the instance of secondary image and appropriate location
        //The following snippet tries to draw the secondary image at the right bottom of the primary image
        graphics.DrawImage(signature, new Point(canvas.Height - signature.Height, canvas.Width - signature.Width));
        //Save the result in PNG format
        canvas.Save("D:/output.png", new PngOptions());
    }
}
 
开发人员可以从控件中国网上下载Aspose.Imaging产品的试用版进行该功能的测试,如果有什么不清楚的也可以随时联系我们。
 
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat