>I was wondering if theres some way to copy the bitmap contents to a constant string, then load it?
Check out this code by JaWib.
Code:
#include <windows.h>
#include <iostream>
class Bitmap
{
public:
Bitmap(const char* file)
{
m_hImage = (HBITMAP)LoadImage(GetModuleHandle(0),file,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
}
bool operator!() { return m_hImage==0?true:false; }
void Draw()
{
HDC hdc = GetDC(GetConsoleWindow());
BITMAPINFO bmi = {0};
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
if (!GetDIBits(hdc,m_hImage,0,0,0,&bmi,DIB_RGB_COLORS))
std::cerr<<"Failed to get bitmap info";
int width = bmi.bmiHeader.biWidth;
int height = bmi.bmiHeader.biHeight;
char* bits = new char[width*height*bmi.bmiHeader.biBitCount+sizeof(BITMAPINFOHEADER)];
memcpy(bits, &bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
if(!GetDIBits(hdc, m_hImage, 0, height, bits+bmi.bmiHeader.biSize, (LPBITMAPINFO)bits, DIB_RGB_COLORS))
std::cerr<<"Failed to get bits: "<<GetLastError();
if (!SetDIBitsToDevice(hdc,0,0,width,height,0,0,0,height,bits+bmi.bmiHeader.biSize,(LPBITMAPINFO)bits,DIB_RGB_COLORS))
std::cerr<<"Failed to draw"<<GetLastError();
ReleaseDC(GetConsoleWindow(),hdc);
}
private:
HBITMAP m_hImage;
};
std::ostream& operator<<(std::ostream& os, Bitmap& image)
{
image.Draw();
return os;
}
int main()
{
Bitmap image("image.bmp");
if(!image)
{
std::cerr<<"Failed to load image";
return 1;
}
std::cout<<image;
}
It was posted under this thread: http://cboard.cprogramming.com/showthread.php?t=82192