Click here to Skip to main content
15,891,853 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am totally beginner,,i'd like to get pixel value from a bitmap..msdn doesnt help me much, help me how to obtain an image, than get the pixel value from it..with c++ with a simple code...

Thanks..
Posted
Comments
Sergey Alexandrovich Kryukov 8-Aug-11 1:17am    
Please: platform (from "MSDN" one could guess it's Windows, but why guessing?), its version(s), UI library/API, version. Tag it all. What did you try, what are the problems?
--SA
ThatsAlok 8-Aug-11 2:21am    
Hai Kay,

could you confirm your compiler i.e. turbo c++ or visual studio \?
Albert Holguin 8-Aug-11 15:58pm    
You can pretty much guess with his remark about msdn, besides, the compiler doesn't make the difference here... the framework or libraries will.
Kay Andrian Fikar 13-Aug-11 1:03am    
i tried to use bitmap class like this:

#include "windows.h"
#include "gdiplus.h"
#include "stdio.h"
#include "stdafx.h"
#include "iostream"
using namespace Gdiplus;

void main()
{

Bitmap* mybitmap;
mybitmap = gcnew("C:\\Users\\USER\\Documents\\rumah.bmp",false);
int x;
int y;
Color pixelcolor[1000][1000];
for ( x = 0; x < mybitmap->Width; x++ )
{
for ( y = 0; y < mybitmap->Height; y++ )
{
Color pixelcolor[x][y] = mybitmap->GetPixel( x, y );
cout << "Pixel color " << x << ", " << y; "is " << pixelcolor[x][y];
}
}
printf("The width of the image is %u.\n", image->GetWidth());
printf("The height of the image is %u.\n", image->GetHeight());

}</pre>
Error list:

Error 3 error C2871: 'Gdiplus' : a namespace with this name does not exist c:\users\user\documents\visual studio 2008\projects\getpixel\getpixel\getpixel.cpp 6 Error 4 error C2065: 'Bitmap' : undeclared identifier c:\users\user\documents\visual studio 2008\projects\getpixel\getpixel\getpixel.cpp 11

I dont know why Gdiplus namespace doesn't exist... Could you give me some thinking?

Use the class Bitmap, constructor/Save method for file read/write, GetPixel/SetPixel for individual pixel access, LockBits/Unlock bits for accessing the whole array of pixels.
 
Share this answer
 
v3
MSDN helps you plenty, you just need to know enough to understand it. Get/SetPixel is very slow in C++, create a DIBSECTION instead, and you'll have fast access to the underlying pixel data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900