效果图

1 配置Gdiplus

    (1)下载GDI+ for VC6.0 SDK 文件,下载地址 http://pan.baidu.com/s/1pKFEGC7 
  
    (2)新建一个VC6的工程(win32 application).选择典型的hello world.
    (3)把压缩包内“复制里面的内容到VC6工程目录下”文件夹内的内容复制到工程目录下.
    (4)打开自动生成的cpp文件.
    (5)在cpp最前面添加代码:(引用头文件和库,使用GdiPlus命名空间)

#pragma comment(linker, "/subsystem:windows")
#include<windows.h>
#define ULONG_PTR unsigned long
#include "gdiplus/GdiPlus.h"
#pragma comment(lib, "GdiPlus.lib")
using namespace Gdiplus;
    (6)添加两个全局变量(Global Variables),一个是要显示的png,一个是背景图(在上面的下载地址里有这两个图片)
      Image *g_png1;Image *g_back1;
    (7)找到WinMain函数,在MyRegisterClass(hInstance);后面添加三行.用于GdiPlus的初始化.
    GdiplusStartupInput gdiplusstartupinput;ULONG_PTR gdiplustoken;GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL);

(8)在WinMain函数的return之前添加一行,用于关闭程序时GdiPlus的资源回收.

        GdiplusShutdown(gdiplustoken);

2 修改WM_PAINT消息的处理

    (1)找到WndProc函数,在开头的声明部分添加:
 //使用双缓冲防止屏幕闪烁HDC hdc_buffer;//缓冲的DCHBITMAP m_hSurface;//缓冲的位图

    (2)找到WndProc函数,在switch (message) 的case WM_PAINT:下添加以下代码:
    hdc = BeginPaint(hWnd, &ps);//开始绘图hdc_buffer = CreateCompatibleDC(NULL);//创建一个空的DCm_hSurface = CreateCompatibleBitmap(hdc, WINDOWS_WIDTH, WINDOWS_HEIGHT);//创建一个与屏幕大小相同的空图片,宽和高可以自己设置SelectObject(hdc_buffer, m_hSurface);//选择对象OnPaint(hdc_buffer);//这个OnPAINT是自己写的函数BitBlt(hdc, 0, 0, 1024, 768, hdc_buffer, 0, 0, SRCCOPY);EndPaint(hWnd, &ps);//结束绘画DeleteObject(m_hSurface);//释放内存DeleteObject(hdc_buffer);//释放内存InvalidateRect(hWnd, NULL, FALSE);//重绘所有区域 这样一结束绘图就又会收到系统的WM_PAINT消息 所以一直在重绘break;

(3)添加自己的OnPaint函数

//  FUNCTION:  OnPaint(HDC hdc)
//
//  CREATED BY YOURSELF
//
//  PURPOSE:Paint on the hdc
//
void OnPaint(HDC hdc){static double i2;//0-15计数用的 图片中一共有16个子图片static double dPos;Graphics graphics(hdc);graphics.DrawImage(g_back1,0, 0, 0, 0, 800, 600, UnitPixel);//画背景graphics.DrawImage(g_png1,(int)dPos, 200, ((int)i2 % 4) * 32, 2 * 32, 32, 32, UnitPixel);//画png//参数为 Image* image,INT x,INT y,INT srcx,INT srcy,INT srcwidth,INT srcheight,Unit srcUnit)i2=i2+0.04;if (i2>15)i2=0;dPos+=0.35 ;if (dPos > WINDOWS_WIDTH) dPos =0;
}

(4)编译-运行就OK啦~

附:完整代码(在VC6可直接编译运行(需要配置好环境))

// win32.cpp : Defines the entry point for the application.
//#define IDI_WIN32             107
#define IDI_SMALL               108
#define IDC_WIN32               109#pragma comment(linker, "/subsystem:windows")
#include <string>
#include <stdlib.h>
#include<windows.h>#define ULONG_PTR unsigned long
#include "gdiplus/GdiPlus.h"#pragma comment(lib, "GdiPlus.lib")using namespace Gdiplus;#define MAX_LOADSTRING 100
#define WINDOWS_WIDTH 400
#define WINDOWS_HEIGHT 300//ULONG_PTR        m_gdiplusToken;// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                              // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];                                // The title bar textImage *g_png1;
Image *g_back1;// Foward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
//LRESULT CALLBACK  About(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR     lpCmdLine,int       nCmdShow)
{MSG msg;MyRegisterClass(hInstance);//  Initialize GdiPlusGdiplusStartupInput gdiplusstartupinput;ULONG_PTR gdiplustoken;GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL);// Perform application initialization:if (!InitInstance (hInstance, nCmdShow)) {return FALSE;}//hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WIN32);// Main message loop:while (GetMessage(&msg, NULL, 0, 0)) {//if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) //   {TranslateMessage(&msg);DispatchMessage(&msg);//    }}GdiplusShutdown(gdiplustoken);return msg.wParam;
}//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{WNDCLASSEX wcex;wcex.cbSize = sizeof(WNDCLASSEX); wcex.style          = CS_HREDRAW | CS_VREDRAW;wcex.lpfnWndProc = (WNDPROC)WndProc;wcex.cbClsExtra     = 0;wcex.cbWndExtra        = 0;wcex.hInstance     = hInstance;wcex.hIcon         =   LoadIcon(hInstance, (LPCTSTR)IDI_WIN32);wcex.hCursor       = LoadCursor(NULL, IDC_ARROW);wcex.hbrBackground   = (HBRUSH)(COLOR_WINDOW);//Grey Colorwcex.lpszMenuName =(LPCSTR)IDC_WIN32;wcex.lpszClassName  = "WIN32";wcex.hIconSm       = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);return RegisterClassEx(&wcex);
}//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{HWND hWnd;hInst = hInstance; // Store instance handle in our global variablehWnd = CreateWindow("WIN32", "win32", WS_OVERLAPPEDWINDOW,400, 300, WINDOWS_WIDTH, WINDOWS_HEIGHT, NULL, NULL, hInstance, NULL);if (!hWnd){return FALSE;}ShowWindow(hWnd, nCmdShow);UpdateWindow(hWnd);return TRUE;
}//
//  FUNCTION:  OnPaint(HDC hdc)
//
//  CREATED BY YOURSELF
//
//  PURPOSE:Paint on the hdc
//
void OnPaint(HDC hdc){static double i2;//0-15计数用的 图片中一共有16个子图片static double dPos;Graphics graphics(hdc);graphics.DrawImage(g_back1,0, 0, 0, 0, 800, 600, UnitPixel);//画背景graphics.DrawImage(g_png1,(int)dPos, 200, ((int)i2 % 4) * 32, 2 * 32, 32, 32, UnitPixel);//画png//Image* image,INT x,INT y,INT srcx,INT srcy,INT srcwidth,INT srcheight,Unit srcUnit)i2=i2+0.04;if (i2>15)i2=0;dPos+=0.35 ;if (dPos > WINDOWS_WIDTH) dPos =0;
}//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND  - process the application menu
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{int wmId, wmEvent;PAINTSTRUCT ps;HDC hdc;//使用双缓冲防止屏幕闪烁HDC hdc_buffer;//缓冲的DCHBITMAP m_hSurface;//缓冲的位图//   LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);switch (message) {case WM_CREATE:g_png1 = new Image(L"1.png", FALSE);//载入pngg_back1 = new Image(L"back.png", FALSE);//载入背景break;case WM_COMMAND:wmId    = LOWORD(wParam); wmEvent = HIWORD(wParam); switch (wmId){case 1:default:return DefWindowProc(hWnd, message, wParam, lParam);}break;case WM_PAINT:hdc = BeginPaint(hWnd, &ps);//开始绘图// TODO: Add any drawing code here...hdc_buffer = CreateCompatibleDC(NULL);//创建一个空的DCm_hSurface = CreateCompatibleBitmap(hdc, WINDOWS_WIDTH, WINDOWS_HEIGHT);//创建一个与屏幕大小相同的空图片SelectObject(hdc_buffer, m_hSurface);//选择对象OnPaint(hdc_buffer);//这个OnPAINT是自己写的函数BitBlt(hdc, 0, 0, 1024, 768, hdc_buffer, 0, 0, SRCCOPY);EndPaint(hWnd, &ps);//结束绘画DeleteObject(m_hSurface);//释放内存DeleteObject(hdc_buffer);//释放内存InvalidateRect(hWnd, NULL, FALSE);//重绘所有区域 这样一结束绘图就又会收到系统的WM_PAINT消息 所以一直在重绘break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0;
}// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{switch (message){case WM_INITDIALOG:return TRUE;case WM_COMMAND:if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {EndDialog(hDlg, LOWORD(wParam));return TRUE;}break;}return FALSE;
}

VC6使用GdiPlus绘制png图片相关推荐

  1. ai 临摹图片换背景_AI临摹绘制插画图片

    AI临摹绘制插画图片 1.打开AI,新建一个文档.开始绘制前,首先确定要画对象的透视参考线.观察原图就会找到基于立体的三维轴线(在这里,我们用X,Y,Z轴来表达). 2.先绘制出外边框,边框线的粗细为 ...

  2. python如何将图片的像素矩阵绘制成图片(python,matplotlib):TypeError: Invalid shape (1, 28, 28) for image data

    矩阵变成图片,这个问题使用(python , matplotlib ) 可以轻松实现. import matplotlib.pyplot as plt #使用格式 plt.imshow(x)#其中x为 ...

  3. java canvas 画图片_[Java教程][HTML5] Canvas绘制简单图片

    [Java教程][HTML5] Canvas绘制简单图片 0 2016-05-13 13:00:04 获取Image对象,new出来 定义Image对象的src属性,参数:图片路径 定义Image对象 ...

  4. 【Android 应用开发】Paint 渲染 之 BitmapShader 位图渲染 ( 渲染流程 | CLAMP 拉伸最后像素 | REPEAT 重复绘制图片 | MIRROR 绘制反向图片 )

    文章目录 1. 位图渲染 BitmapShader 简介 ( 1 ) 位图渲染综述 ( ① 三种方式 : Shader.TileMode.CLAMP | Shader.TileMode.REPEAT ...

  5. 解决《Mobile绘制背景图片》中的问题

    与PC平台的开发相比,Mobile的开发麻烦了许多,至少这是我的感觉 . 谢谢--" Fly Pig(^@^)" 的文章<Mobile开发(绘制背景图片) > http ...

  6. html5中Canvas、绘制线条模糊、常见绘制工具、绘制基本图形、绘制图片、面向对象的方式绘制图形图片、绘制文本、帧动画绘制

    Canvas容器: canvas标签用来定义图像的容器,必须配合脚本来绘制图像,canvas也运用于游戏开发.注意:canvas绘制图时会出现线条模糊情况,这是因为显示屏像素和canvas中定义的一个 ...

  7. UIImageView绘制圆形图片

    参考网上的资料,自实现了一个UIImageView绘制圆形图片功能. 先看效果: 代码如下: - (void)buttonAction:(id)sender { //方式1,见上图的方式1效果.通过i ...

  8. python绘制决策树图片

    背景 w3cshool机器学习篇最后一个章节是决策树的简单入门教学,我在那里拷贝代码运行时报错,显示绘制不出决策树图片 思路 python编译报错无非三种,语法错误,没有装库,路径没对.w3cshoo ...

  9. 使用gdiplus显示gif图片

    使用gdiplus显示gif图片 需求 在没有MFC上下文的windows环境下实现gif图片的显示: 可以根据文件名来显示gif图片: gif图片集成到可执行程序中. 实现思路 windows ap ...

最新文章

  1. abortonerror_离线打包白屏
  2. 一文了解OOM及解决方案,成功入职字节跳动
  3. Win32 API CreateCompatibleDC 函数的相关应用
  4. A Hands-on Look at Using Ray Tracing in Games with UE 4.22 GDC 2019
  5. java 对象锁定_少锁定Java对象池
  6. linux6.7能升级6.8吗,CentOS 六、7升级gcc至4.八、4.九、5.二、6.三、7.3等高版本
  7. 知识图谱论文阅读(二十)【WWW2020】Heterogeneous Graph Transformer
  8. Vue商品添加到购物车
  9. 机械硬盘 运行 linux 很慢,如果读写硬盘操作有问题,假死机、很慢等,就检查一下硬盘坏道...
  10. matlab计算三角格网面积,不规则平面图形的面积计算及其MATLAB实现.doc
  11. 网站压力测试工具Webbench介绍
  12. 根据 ”艾宾浩斯遗忘曲线“复习时间点生成的复习计划模板
  13. 2022年疑点事件:NMN到底是什么?nmn到底有没有用?
  14. 【ME909】华为ME909 4G LTE模块在树莓派下通过minicom进行发送短信演示
  15. python股票预测_python用线性回归预测股票价格的实现代码
  16. 组播MAC地址和各类IP地址
  17. 经典SQL练习——详细到令人发指(未完待续)
  18. 浅谈防火墙对 FTP 的影响及故障排除
  19. Unity-解决报错Shader error in ‘EffectCore/alphaBlend_glow‘: ‘‘ : ‘UNITY_PASS_FORWARDBASE‘ already define
  20. 思科640-816最新认证资料-Pass4side权威考题大师提供

热门文章

  1. 微信摇一摇效果HTML,JavaScript+H5实现微信摇一摇功能
  2. ERDAS2013安装资源及破解步骤
  3. TerraExplorer Add-ons 和TEZ使用说明
  4. 基于高光谱成像的苹果虫害检测特征向量的选取
  5. c语言中指数函数fabs,高一指数函数公式,高一指数函数
  6. HDMI ARC功能详解及应用介绍
  7. 网易互娱 实习生招聘 内推
  8. OpenCV (c++)使用KDTree时,得到正确结果后报Segmentation fault (core dumped)
  9. R 两组样本t检验 wilcoxon检验、卡方、fisher精确检验
  10. 武则天用无字碑深切蔑视男人