Archived

This topic is now archived and is closed to further replies.

dachande

Using gdiPlus

Recommended Posts

Hey, Has anybody here had experience with gdi+ in C++ ? I have written the following code:
#include 
#include 

Color myColor;
 
and am already receiving errors... The compiler is not picking up that ''Color'' is a container/class. I have tried specifically including gdiplusColor.h where the Color class is built, but have had no luck in compiling the app. Similar problems are met when using the Bitmap class (created in gdiPlusBitmap.h) What''s the secret to using GDI+ ? Thanks, Dachande

Share this post


Link to post
Share on other sites
Thank you for your help, my application now compiles properly. However, I am still suffernig from erronous output.

The file the program is meant to create outputs a 1 or a 0 depending upon if a pixel in a bitmap is white or not. unfortunately, all the file is made of is numerous 0''s. Perhaps someone could give me a hint as to why the bitmap is not being read properly, or point me in the direction of more appropriate code? :


#include
#include
#include

using namespace Gdiplus;

struct collision {
byte hit[1024][1024];
};

collision myCollision;
Color pixelColor;

int main() {
Bitmap myBitmap(L"test.JPG");

for (int x = 0; x < 1024; x++) {
for (int y = 0; y < 1024; y++) {
myBitmap.GetPixel(x, y, &pixelColor);

if (pixelColor.GetValue() == Color::White) myCollision.hit[x][y] = 1;
else myCollision.hit[x][y] = 0;

}
}

ofstream dbOut;
dbOut.open("test.dat", ios::binary);
dbOut.write((char *)(&myCollision), sizeof(myCollision));
dbOut.close();
return 0;
}


If you have any suggestions I would be gratful to hear any of them,

Thanks again,

Dachande

Share this post


Link to post
Share on other sites
quote:
Original post by dachande
	ofstream dbOut;
dbOut.open("test.dat", ios::binary);
dbOut.write((char *)(&myCollision), sizeof(myCollision));
dbOut.close();
return 0;
}


There are certain peculiarities when it comes to writing data out with ofstream in binary mode. It doesn''t do exactly what you expect. I''m away from my computer (and reference materials), so I''ll have to ask you to follow that up yourself...

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
Thank you for your suggestion, I have never had a problem using fstream before, in fact it has been great throughout my other trials and tribulations. I''m using it in a similar fashion in many other situations, so just for now, I would like to check for other errors and come back to my output code if I find myself at a dead end.

Perhaps there is a better way to get the pixel data from a db than using gdi+? The code there is nice and simple, but I am happy to sacrifice simplicity for working code

Thanks,

Dachande

Share this post


Link to post
Share on other sites
Are you sure your whites are white? I noticed you were using a jpeg, and it''s possible (through the magic of lossy compression) that a color you may be expecting to be RGB(255,255,255) is coming up closer to RGB(253,253,253) or something.

Just a thought,
-scott

Share this post


Link to post
Share on other sites
Thank you for you suggestion, however, I am using clumps of white... only the outside colour would have changed... but I tested the code with a bmp earlier on to make sure it was not the loading code that had problems.

Thanks anyway,

Dachande

Share this post


Link to post
Share on other sites