loading
 
API getImage function
Anonymous
9 years
What format does the image come in when using the getImage function in the roborealm api?? In c++ how can this be changed so that it can be displayed in a picture box?
Anonymous 9 years
Im using this code to get the image usiong the GetImage function and then I loop it into a byte array to change into a bitmap image:

array <Byte>^ imageBytes = gcnew array<Byte>(320*256*3);
    int width = 320;
    int height = 256;
    // get the current image dimention
    //rr.getDimension(&width, &height);
    rr.getImage("processed",image, &width, &height, 320*256*3);
    
    for(int i=0; i<(320*256*3);i++)
    {
        imageBytes[i]=(unsigned char)image;
        *image++;
    }

The problem is the imageBytes array ends up being filled with characters that starts with "hijklmnop" The resulting image after i change it into a bitmap is shown in image 1. The code I use to change the rgb values into bitmap is shown below:

Bitmap^ Getimage(array<Byte>^ image, int width, int height)
{
int x;
int y;
int counter = 0;
Bitmap^ ProcessedImage = gcnew Bitmap(width, height, PixelFormat::Format24bppRgb);
    
for(x=0; x<ProcessedImage->Width; x++)
        {
            for(y=0; y<ProcessedImage->Height; y++)
            {
    int i=(height*x+y);
    int r = Convert::ToUInt16(image[3*i]);
    int g = Convert::ToUInt16(image[3*i+1]);
    int b = Convert::ToUInt16(image[3*i+2]);
    Color newColor = Color::FromArgb(r, g, b);
                ProcessedImage->SetPixel(x, y, newColor);
            }
        }

    // Loop through the images pixels to set color.
    
    return ProcessedImage;
}

The image currently in roborealm at the time is shown as image 2

Anonymous 9 years
int i=(height*x+y);

should probably be

int i=((width*y)+x);

but that would still not account for the image above. How are you calling GetImage? With image or imageBytes??

Also check width and height after rr.getImage just to be sure you got the image you think you did.

STeven.
Anonymous 9 years
You got the format correct it is 24 bits of pixel data in 3 bytes Red, Green, Blue in sequence. You loop through with a step of 3 to get from pixel to pixel.

STeven.
Anonymous 9 years
The Getimage function is called with the imagebytes array. Am I looping the recieved image pointer into an array correctly? I kept on getting the same characters in the imagebytes array no matter what image was in roborealm
Anonymous 9 years
This part appears incorrect:

   for(int i=0; i<(320*256*3);i++)
    {
        imageBytes[i]=(unsigned char)image;
        *image++;
    }

perhaps

   for(int i=0; i<(320*256*3);i++)
   {
        imageBytes[i]=(unsigned char)image[i];
   }

would simplify and do the trick ... the image you attached is basically one you get when you are not assigning the actual data but instead creating an image out of the iterator ..which appears to be happening in your code.

Note that we also added a sample application into the API.zip download that shows how to use the API in a dialog based APP to get a bitmap (a new getBitmap API call was added) and show that image in a dialog. It is in C++ using VC6.0 to keep things very basic ... but you might find that useful if the above correction does not work out.

STeven.

Anonymous 9 years
When I try this I just get an imageBytes array filled with a funny I character (0xcd in hex).
Anonymous 9 years
Then most probably your "image" is not filled correctly.

Can you post your entire project as a .zip file to one of the upload sites (just search for one that you want to use using Google) and paste the link here. Then we can try to replicate your issue and provide a solution.

STeven.
Anonymous 9 years
I used your code again and got rid of some other code that was interfering with it and it works! Thanks! Now I just need to try to get the getBitmap function working (problem posted in another post)

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index