For Programmers: Free Programming Magazines  


Home > Archive > VC Language > May 2006 > problem in transferring the bitmap values to a 1D array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author problem in transferring the bitmap values to a 1D array
kkirtac

2006-05-27, 8:07 am

here is the code snippet :

#define INDEX(W, R, C) ((R)*(W)+(C)) //defined in Tools.h

//starts Form1.h
......
.......
.......
static int arrayVal ;
static int* img; //the 1D array
static Bitmap* source; // source image
Bitmap* gray; // gray image
....
....
....

public: System::Void openFileDialog1_FileOk(System::Object * sender,
System::ComponentModel::CancelEventArgs * e) {

source = new Bitmap(Image::FromFile(openFileDialog1->FileName));
gray = ConvertToGrayscale( source ) ; // ConvertToGrayScale is defined in

//Tools.h

img = (int*) new int[(gray->Width)*(gray->Height)] ;

for(int row=0; row < gray->Height; row++)
for(int col=1; col < gray->Width; col++)
{
a = (gray->GetPixel(col,row)).R;
img[ INDEX(gray->Width, row, col) ] = (gray->GetPixel(col,row)).R ;
}

//when i check the "a" value with debugger in the first iteration, it shows
//149 and when i check the img[1] value it shows 39 ; so shouldn't the
//img[1] value be 149 too ?? what's my mistake can anyone guess where i
//am wrong?
kkirtac

2006-05-27, 7:05 pm

ok the problem is fixed, declaring img as static had caused the error...

"kkirtac" wrote:

> here is the code snippet :
>
> #define INDEX(W, R, C) ((R)*(W)+(C)) //defined in Tools.h
>
> //starts Form1.h
> .....
> ......
> ......
> static int arrayVal ;
> static int* img; //the 1D array
> static Bitmap* source; // source image
> Bitmap* gray; // gray image
> ...
> ...
> ...
>
> public: System::Void openFileDialog1_FileOk(System::Object * sender,
> System::ComponentModel::CancelEventArgs * e) {
>
> source = new Bitmap(Image::FromFile(openFileDialog1->FileName));
> gray = ConvertToGrayscale( source ) ; // ConvertToGrayScale is defined in
>
> //Tools.h
>
> img = (int*) new int[(gray->Width)*(gray->Height)] ;
>
> for(int row=0; row < gray->Height; row++)
> for(int col=1; col < gray->Width; col++)
> {
> a = (gray->GetPixel(col,row)).R;
> img[ INDEX(gray->Width, row, col) ] = (gray->GetPixel(col,row)).R ;
> }
>
> //when i check the "a" value with debugger in the first iteration, it shows
> //149 and when i check the img[1] value it shows 39 ; so shouldn't the
> //img[1] value be 149 too ?? what's my mistake can anyone guess where i
> //am wrong?

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com