win32 往图片中写水印
来源:互联网 发布:用友沙盘模拟软件 编辑:程序博客网 时间:2024/05/18 01:26
整理自己的代码文件夹发现了自己写的一个往图片中写水印的方法。恩,这等方法要写出来,差点就删掉了。\(^o^)/~貌似是自己看照公司的代码一个个的抄在笔记本上然后又一个个的敲到电脑里的,真他妈的辛苦我自己了。附上代码,有需要的尽管拿;
#pragma comment(lib,"gdiplus.lib")#pragma once#include "windows.h"#include "gdiplus.h"#include <stdio.h>#include "Tchar.h"#include "string.h"#include "math.h"#include <valarray>using namespace std;using namespace Gdiplus;///////////////////some information user define ///////////////////////#define MAINFRAME _T( "mainfram")HWND Hwnd=NULL;///////////////////////////////////////////////////////////////////////LRESULT CALLBACK MainFrame(HWND, UINT, WPARAM, LPARAM);//////////this function purpose is to get the clsid of the image specified by me//////////20121121 by cq//////////////int GetEncoderClsid(const WCHAR* format, CLSID* pClsid){ UINT num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); if(pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j) { if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 ) { *pClsid = pImageCodecInfo[j].Clsid; free(pImageCodecInfo); return j; // Success } } free(pImageCodecInfo); return -1; // Failure}/////////////////////////////////////////////////20121121 by cq ///////////////////this function purpose is to add some words into the image ///////// we can adjust the ARGB(A,R,G,B) of the word A means the ALPHA, a=0 means transparent///////// here i uesed my english name "linhar" and add the loacl time into the pictureImage* WaterMarking(WCHAR *ImageFile,int width,int height){ /*HBITMAP pbmp; pbmp=LoadBitmap( HPALETTE hpal=NULL; Bitmap bmp(pbmp,hpal); Graphics g(&bmp);*/Image *image=new Image(ImageFile);//for the test~~~~~~~~~~~//printf("The width of the image is %u.\n", image->GetWidth()); //printf("The height of the image is %u.\n", image->GetHeight());//~~~~~~~~~~~~~~~~~~~~~~~Graphics g(image);SYSTEMTIME stUTC,stLocal;GetSystemTime(&stUTC);TCHAR time[128];TCHAR userString[128]=L"cqtest";SystemTimeToTzSpecificLocalTime(NULL,&stUTC,&stLocal);_stprintf(time,L"%d-%d-%d %d:%d",stLocal.wYear,stLocal.wMonth,stLocal.wDay,stLocal.wHour,stLocal.wMinute);double angle =atan2((double)height,(double)width);double degree =angle*180/3.1415926;double chord =sqrt((double)width*width+(double)height*height);double fontsize=chord/20;double foxPointY=height-fontsize;FontFamily fontFamily(L"Times New Roman");Font foxFont(&fontFamily,(REAL)fontsize,FontStyleBold,UnitPixel);PointF foxPoint((REAL)fontsize,(REAL)foxPointY);//PointF foxPoint((REAL)15,(REAL)200);SolidBrush brush(Color(100,0,0,0));Matrix matrix;matrix.Translate(40.0f,0.0f);matrix.RotateAt((REAL)-degree,foxPoint,MatrixOrderAppend);g.SetTransform(&matrix);_tcscat(userString,time);g.DrawString(userString,15,&foxFont,foxPoint,&brush);////////////////////////////////////////////////////CLSID Clsid;//--------------------------------------GetEncoderClsid(L"image/jpeg", &Clsid);image->Save(L"test.jpg", &Clsid);//save the watered picture to local disc////////////////////////////////////////////////////return image;}//////////////////////////////////////////////////////////////////this function is to register a window///////////20121124 by cqbool MY_RegisterClass(WNDCLASS & wndclass){wndclass.cbClsExtra=0;wndclass.cbWndExtra=0;wndclass.hbrBackground=(HBRUSH)GetStockObject(LTGRAY_BRUSH);wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);wndclass.hInstance=GetModuleHandle(NULL);wndclass.lpfnWndProc=MainFrame;wndclass.lpszClassName=MAINFRAME;wndclass.lpszMenuName=NULL;wndclass.style=NULL;if(!RegisterClass(&wndclass)){return false;}return true;}////////////////////////////////////////////////////////////////this function purpose is to create a window register by the function MY_RegisterClassbool MY_CreateWindow(){Hwnd=CreateWindowEx(NULL,MAINFRAME,_T("Image"),WS_SYSMENU|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT, 400, 300, NULL, NULL, GetModuleHandle(NULL), NULL);if(!Hwnd){ShowWindow(Hwnd,SW_SHOWNORMAL);UpdateWindow(Hwnd);return true;}else{return false;}}//////////////////////////////////////////////////////LRESULT CALLBACK MainFrame(HWND, UINT, WPARAM, LPARAM){return 0;}int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ){GdiplusStartupInput gdiplusStartupInput;ULONG_PTR gdiplusToken;GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);WNDCLASS WndClass;if(!MY_RegisterClass(WndClass)){::MessageBox(NULL,_T("ERROE1"),_T("ERROR"),1);return 0;}else{if(!MY_CreateWindow()){::MessageBox(NULL,_T("ERROE2"),_T("ERROR"),1);return 0;}}//HWND desktop=GetDesktopWindow ();HDC DC=GetDC(Hwnd);Image *image=NULL;WCHAR ImageFile[30]=_T("D:\\CHENQIANG.jpg");Image Temp(ImageFile);Graphics g(DC);const RectF rect(10,10,500,500);image=WaterMarking(ImageFile,500,800);system("pause");g.DrawImage(image,100,10,500,875);Sleep(9000);ReleaseDC(Hwnd,DC);delete image; MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int) msg.wParam;//GdiplusShutdown(gdiplusToken);return 0;}
0 0
- win32 往图片中写水印
- Delphi图片上写水印文字函数
- C#中添加图片水印
- php中图片水印效果
- android中图片水印换行
- photoshop中如何给图片加水印和去水印
- asp.net 中给图片加水印
- Asp.Net中动态实现图片水印
- iOS在图片中添加水印
- iOS中制作一张水印图片
- CSDN博客中图片上的水印
- 如何去掉CSDN中图片水印
- C#写的给图片加水印的实例代码
- 参考phpcms所写的图片添加水印功能
- 多次写文字到图片上的水印效果
- 自己写个小工具——图片水印生成器
- 图片水印
- 图片水印
- 苹果中国供应商再增20家
- hdu1027 Ignatius and the Princess II(排列问题)
- iOS真机调试证书那些事儿
- CCI: Count negative numbers in matrix
- hdu 1018 Big Number 数学
- win32 往图片中写水印
- C++ ”类“ 知识的回顾
- 第六周作业
- paip.输入法编程---词库多意义条目分割 python实现.
- Dll中运用vector的堆栈崩溃
- 萌神吃土豆007 (zoj 3676 - 3685)
- 顺序图
- paip.代码生成器数据源格式最佳实践
- 后端技术流博客收藏