1,在调用窗体里,Unit1.cpp里引入

#include "WaterMark.h"




2,在窗体加载事件里加载动态库:



__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
       //初始化水印
       if(!LoadWaterMark())
       {
           ShowMessage("加载水印失败!");
       }
}




3,触发添加水印



void __fastcall TForm1::Button1Click(TObject *Sender)
{
    //添加水印
    AnsiString imgPath="D:\\img\\tempImg.jpg";
    int suc=WaterMarkEmbed(s.c_str(),"water.bmp");
//返回:1成功
//0失败
//-1文件类型不对,或者已经加密过
//-2水印文件不符合,太大
//-3文件有问题,或者文件名不对,文件要带扩展名
}




拷贝WaterMark.cpp和WaterMark.h文件到工程目录中



打开工程文件,点击菜单栏中工程->添加到工程,选中刚拷贝过来的那两个文件



WaterMark.cpp



#include <vcl.h>
#pragma hdrstop

#include "WaterMark.h"
#include <stdio.h>

int (WINAPI *lpfnWaterMarkEmbed)(char * FilePath,char * WaterMarkFilePath);

int (WINAPI *lpfnPicIsTamper)(char* FilePath);

bool LoadWaterMark()
{
       RMDLL=LoadLibrary("WaterMarkDll.dll");
       if (!RMDLL)
                return false;

       (FARPROC )lpfnWaterMarkEmbed=GetProcAddress(RMDLL,"_WaterMarkEmbed@8");         //加载图片
       (FARPROC )lpfnPicIsTamper=GetProcAddress(RMDLL,"_PicIsTamper@4"); // 图片识别用
        return true;
}
//添加水印
int WaterMarkEmbed(char * FilePath,char * WaterMarkFilePath)
{
      return lpfnWaterMarkEmbed(FilePath,WaterMarkFilePath);
}
//验证
int PicIsTamper(char* FilePath)
{
     return lpfnPicIsTamper(FilePath);
}
#pragma package(smart_init)




WaterMark.h



#ifndef WaterMarkH
#define WaterMarkH

HANDLE RMDLL;

bool LoadWaterMark(); //加载水印模块动态连接库

int WaterMarkEmbed(char * FilePath,char * WaterMarkFilePath); 

int PicIsTamper(char* FilePath);

#endif




[color=red]不提供下载[/color],下载链接为我自己备份使用,内带防篡改图片验证程序,WaterMarkDll.dll和一张水印图,压缩包有密码,请勿下载



黑色头发:http://heisetoufa.iteye.com/