GDI+ 读取(jpg,PNG,BMP)等格式)图片每个像素的值
来源:互联网 发布:客户满意率的数据来源 编辑:程序博客网 时间:2024/05/18 03:43
感觉作为一个学图形学的,还是可能偶尔要亲自读取纹理的,这里有篇技术博客介绍用GDI+读取图片像素
原博客地址:http://blog.csdn.net/wangyaninglm/article/details/41868599
#include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <windows.h> #include <gdiplus.h> #pragma comment(lib, "gdiplus.lib") using namespace std;using namespace Gdiplus;int main(){GdiplusStartupInput gdiplusstartupinput;ULONG_PTR gdiplustoken;GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL);wstring infilename(L"1.jpg");string outfilename("color.txt");//读图片 Bitmap* bmp = new Bitmap(infilename.c_str());UINT height = bmp->GetHeight();UINT width = bmp->GetWidth();cout << "width " << width << ", height " << height << endl;Color color;ofstream fout(outfilename.c_str());for (int y = 0; y < height; y++)for (int x = 0; x < width; x++){bmp->GetPixel(x, y, &color);fout << x << ";" << y << ";"<< (int)color.GetRed() << ";"<< (int)color.GetGreen() << ";"<< (int)color.GetBlue() << endl;}fout.close();delete bmp;GdiplusShutdown(gdiplustoken);return 0;}
BYTE *TextureBuffer;void LoadTexture(wstring TexureFilename){Gdiplus::GdiplusStartupInput gdiplusstartupinput;Gdiplus::Color color;ULONG_PTR gdiplustoken;Gdiplus::GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL); //读取纹理 texture= new Gdiplus::Bitmap(TexureFilename.c_str()); //获取纹理分辨率的宽度和高度 texture_h = texture->GetHeight(); texture_w = texture->GetWidth(); //创建纹理缓存,screen_h*screen_w * 3个字节大 TextureBuffer = new BYTE[texture_h*texture_w * 3]; for (int i = 0; i < texture_h; ++i) { for (int j = 0; j <texture_w; ++j) { //获取相应数组[j][i]的像素,注意这里下标从0开始 texture->GetPixel(j, i, &color); //将像素的颜色输入纹理缓存,注意颜色的顺序应该是BGR TextureBuffer[i * texture_w * 3 + (j + 1) * 3 - 1] = color.GetR(); TextureBuffer[i * texture_w * 3 + (j + 1) * 3 - 2] = color.GetG(); TextureBuffer[i * texture_w * 3 + (j + 1) * 3 - 3] = color.GetB(); } } Gdiplus::GdiplusShutdown(gdiplustoken);}
0 0
- GDI+ 读取(jpg,PNG,BMP)等格式)图片每个像素的值
- GDI+ 读取jpg图片每个像素的值
- VB6.0用GDI+保存图片为JPG、TIFF、PNG、GIF、BMP等格式
- VB6.0用GDI+保存图片为JPG、TIFF、PNG、GIF、BMP等格式
- vc6.0使用gdi+在内存中绘图并将其保存为bmp,jpg,gif,png等格式的图片
- vc6.0使用gdi+在内存中绘图并将其保存为bmp,jpg,gif,png等格式的图片
- GDI+实例教程之: 转换Image(BMP,JPG,GIF,PNG等) 到MetaFile(EMF等) 格式
- VB60用 GDI+保存为JPG/TIFF/PNG/GIF/BMP等格式
- 保存为BMP,Jpg,Png格式的图片
- 获取JPG或者BMP图片的像素
- 获取JPG或者BMP图片的像素
- VB60 使用GDI++转BMP/JPG/等格式的源程序,作者laviewpbt
- 各种图片编码格式详解(bmp,jpg,png)
- Qt之生成png/jpg/bmp格式图片
- Windows Mobile 上显示png,jpg,bmp等图片
- 如何加载显示jpg ,png bmp等图片,利用CImage
- WTL基础: 显示图片(JPG, BMP, PNG, TIF等)
- WTL基础: 显示图片(JPG, BMP, PNG等)
- ActiveX控件(MFC篇)
- Linux下的C语言编程——sqlite3实现停车场管理系统
- NOIP2012 Day1T1Vigenère 密码 P1079
- 1488 数据结构实验:连通分量个数
- 189. Rotate Array
- GDI+ 读取(jpg,PNG,BMP)等格式)图片每个像素的值
- 11.25
- 安装Linux流量监控工具 - iftop
- Mybatis 查询Bean不包含字段的处理
- Redis系列之Redis配置(一)
- IsBackground对线程的重要作用
- 熟悉这几个常用命令,你就是Linux/Unix的vi高手了。
- 1433. 数码问题
- HDU2088 Box of Bricks