win32加载图片获得像素值
2024-08-28 21:26:38
在写光栅渲染器时,需要加载图片获得像素以便进行纹理插值,试了几种方法发现下面这种比价简单,效率也可以接受
Texture2D是我自己定义的类,其中m_pixelBuffer是一个动态二维数组,每个元素为ZCFLOAT3(自定义类型用来保存颜色rgb值)。
#include "LoadBitmap.h"
#include <windows.h>
#include <gdiplus.h> #include <iostream>
#include <fstream>
#include <sstream> #pragma comment(lib, "gdiplus.lib")
using namespace std;
using namespace Gdiplus; Texture2D MathUtil::LoadBitmapToColorArray(wstring filePath)
{
GdiplusStartupInput gdiplusstartupinput;
ULONG_PTR gdiplustoken;
GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, nullptr); Bitmap* bmp = new Bitmap(filePath.c_str());
if (!bmp)
{
MessageBox(nullptr, "error", "picture path is null!", MB_OK);
delete bmp;
GdiplusShutdown(gdiplustoken);
return Texture2D(,);
}
else
{
UINT height = bmp->GetHeight();
UINT width = bmp->GetWidth();
//Texture2D
Texture2D texture(width, height); Color color; for (int y = ; y < height; y++)
for (int x = ; x < width; x++)
{
bmp->GetPixel(x, y, &color); texture.m_pixelBuffer[x][y] = ZCFLOAT3(
color.GetRed() / .f,
color.GetGreen() / .f,
color.GetBlue() / .f
);
} delete bmp;
GdiplusShutdown(gdiplustoken);
return texture;
} }
最新文章
- HTML <;a>; 标签的 target 属性
- Google Chrome 应用商店上传扩展程序
- C# Socket 入门4 UPD 发送结构体(转)
- HDU 3555 Bomb (数位DP-记忆化搜索模板)
- WCF 绑定(Binding)
- QuickSort 递归 分治
- Android自己定义控件之应用程序首页轮播图
- C#进程间通讯技术-整理。
- 转:C++:从子类访问父类的私有函数
- WebStorm 快捷键一览
- argparse库 学习记录
- MATLAB符号对象与符号运算
- 自制模态窗体闪烁效果: MessageBeep &; FlashWindowEx
- (转)小谈keepalived vip漂移原理与VRRP协议
- ubuntu安装mysql,redis,python-mysqldb
- 廖雪峰Java2面向对象编程-6Java核心类-1字符串和编码
- js 表单序列化为json对象
- windows下dump文件调试
- Mac 平台安装 Android Studio 集成 Android SDK
- Iterable转List