I have to create a bitmap image and thought of doing it in c++. The bitmap will be having a 10x10 pixel where i can assign a 1 or 0 to a particular pixel.
My question is can this be done using c++. If can, how do i start doing one as i am absolutely new to c++ and know nothing about it.
I suggest you do not manually create the bitmap. The library easybmp is perfect for this and is one of the easiest libraries to start using I've ever found.
I found what you mean on easybmp.sourceforge.net but could not quite understand it. Do you know of any tutorial which will guide me through creating a bitmap?
BMP AnImage;
// Set size to 640 × 480
AnImage.SetSize(640,480);
// Set its color depth to 32-bits
AnImage.SetBitDepth(32);
// Set one of the pixels
AnImage(14,18)->Red = 255;
AnImage(14,18)->Green = 255;
AnImage(14,18)->Blue = 255;
AnImage(14,18)->Alpha = 0;
AnImage.WriteToFile("Output.bmp");
Another question came while reading the Easybmp user guide.
Can this easybmp library be used in microsoft visual studio 2008 since there was no compiling instruction given in the web whereas there is instruction for other compiler like Borland?
You have two choices. The very easy latest version (#include the header, make sure you compile the .cpp file along with the rest of your code) or the very very easy previous version, in which you just have to #include the header (there is no cpp file).
Well, very easy for you is not easy for me through...face some problem while trying to build the below source code in Win32 project using microsoft visual studio 2008 and need your help!!
# include "EasyBMP.h"
using namespace std;
int main()
{
BMP AnImage;
AnImage.SetSize (640,480);
AnImage.SetBitDepth (8);
AnImage (14,18) -> Red =255;
AnImage (14,18) -> Green =255;
AnImage (14,18) -> Blue =255;
AnImage (14,18) -> Alpha =0;
AnImage.WriteToFile ("output.bmp");
return 0;
}
What i expect was a bitmap image in a file name "output.bmp" but when i build solution the following error occur;
"error LNK2019: unresolved external symbol "public: __thiscall BMP::~BMP(void)" (??1BMP@@QAE@XZ) referenced in function _main"
Seems like there is some linkage error, but i have include the following header file as per instruction in EasyBMP website in my directory;
Tools > Options > Projects and Solutions > VC++ Directories
Select "Include files" on the combo box under "Show directories for:"
And then add the folder which contain all the 6 header files.
Can you identify where the fault is? Seriously need help as i was dump to do this with no help from academic stuff at all and i know nothing about c++.
#include "EasyBMP.h"
int main()
{
BMP AnImage;
// Set size to 640 × 480
AnImage.SetSize(640,480);
// Set its color depth to 32-bits
AnImage.SetBitDepth(32);
for (int i=1;i<100;i++)
{
for (int j=1; j<100; j++)
{
// Set one of the pixels
AnImage(i,j)->Red = 0;
AnImage(i,j)->Green = 0;
AnImage(i,j)->Blue = 0;
AnImage(i,j)->Alpha = 0;
}
}
AnImage.WriteToFile("Output.bmp");
return 0;
}
Output.bmp is a bitmap file of the expected size with a big black square in it.
It looks to me like you are not compiling the cpp file EasyBMP.cpp in your code. You're using Visual Studio.
Be sure to add EasyBMP.cpp to your project to be compiled. That's what "unresolved external" usually means. You're not compiling EasyBMP.cpp into your project (or missing the library, but easyBMP has no libraries).
this post saved me a lot of trouble, thanks a lot! (was about to give up trying to find a library and write the input and output for bmp's myself which would have been a big waste of time)