GetBitmap function for C# or COM?
from United States  [214 posts]
9 years

Could some kind C++/C# expert out there translate the GetBitmap function found in the COM API source into C#?  The C++ source for the COM API does not compile (error C2661: 'RR_API::getImage' : no overloaded function takes 5 arguments) and the C# API source doesn't include the GetBitmap function at all.

I've tried for several hours to do the translation myself or to fix the COM source without success.  Note that the RR_COM_API.dll file that comes with the main RR distribution does not seem to include the GetBitmap function.

The reason I need the GetBitmap function is I that want to display real-time RoboRealm images in a picture box in my C# form.  Thanks to an earlier post, I can save a RR image to a jpeg disk file, then read it back in as a Bitmap, but I can only do this once since the file is then reported as being in use by the RoboRealm process.  I realize I could use the web server interface to RR to display the image, but I am also using an image processing library that needs the images in Bitmap format.

So in short, it would be great to have a working GetBitmap function in the C# or COM API. :-)

Hoping someone can help!


Anonymous 9 years
Hi Patrick,

   Try the following routine, You will also have to delcare using System.Runtime.InteropServices; in order to get it to work

       // Create RGB24 bitmap from Byte array
        Bitmap BitsToBitmapRGB24(Byte[] bytes, int width, int height)
            //swap RGB to BGR
            Byte tmp;
            for (int x = 3; x < bytes.GetLength(0); x += 3)
                tmp = bytes[(x + 2)];
                bytes[x + 2] = bytes[x];
                bytes[x] = tmp;

            if (bytes.GetLength(0) < width * height * 3)
                return null;

            Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            int i;

            BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                ImageLockMode.WriteOnly, bmp.PixelFormat);

            if (data.Stride == width * 3)
                Marshal.Copy(bytes, 0, data.Scan0, width * height * 3);
                for (i = 0; i < bmp.Height; i++)
                    IntPtr p = new IntPtr(data.Scan0.ToInt32() + data.Stride * i);
                    Marshal.Copy(bytes, i * bmp.Width * 3, p, bmp.Width * 3);


            return bmp;
from United States  [214 posts] 9 years
You totally rock!  Works like a charm.  Many many thanks.

Perhaps this would make a nice addition to the API called RR.getBitmap().


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