When writing a raster renderer, you need to load a picture to get pixels for texture interpolation, and try several methods to find out that the following comparisons are simple, efficient and acceptable
Texture2d is a class of my own definition, where M_pixelbuffer is a dynamic two-dimensional array, with each element ZCFLOAT3 (the custom type is used to hold the color RGB values).
1#include"LoadBitmap.h"2#include <windows.h>3#include <gdiplus.h>4 5#include <iostream>6#include <fstream>7#include <sstream>8 9 #pragmaComment (lib, "Gdiplus.lib")Ten using namespacestd; One using namespaceGdiplus; A - texture2d Mathutil::loadbitmaptocolorarray (wstring filePath) - { the gdiplusstartupinput gdiplusstartupinput; - ulong_ptr Gdiplustoken; -Gdiplusstartup (&gdiplustoken, &gdiplusstartupinput, nullptr); - +bitmap* BMP =NewBitmap (Filepath.c_str ()); - if(!bmp) + { AMessageBox (nullptr,"Error","Picture path is null!", MB_OK); at Deletebmp; - Gdiplusshutdown (gdiplustoken); - returnTexture2d (0,0); - } - Else - { inUINT height = bmp->getheight (); -UINT width = bmp->getwidth (); to //texture2d + texture2d Texture (width, height); - the color color; * $ for(inty =0; Y < height; y++)Panax Notoginseng for(intx =0; x < width; X + +) - { theBmp->getpixel (x, Y, &color); + ATexture.m_pixelbuffer[x][y] =ZCFLOAT3 ( theColor. Getred ()/255. F, +Color. Getgreen ()/255. F, -Color. GetBlue ()/255. F $ ); $ } - - Deletebmp; the Gdiplusshutdown (gdiplustoken); - returnTexture;Wuyi } the -}
Win32 loading images for pixel values