|
GetImage in C# wrapper is borken Adas L [7 posts] |
8 year
|
Using API_WrapperClass in RR_APILib.dll
While using save image works perfectly fine (and I'm able to get the data from disc) using get image with (out object image) param is always null. Howver method is returning number, probably correct one.
|
|
|
Steven Gentner from United States [273 posts] |
8 year
|
Adas,
Can you post a quick snippet here of the code that you are using? For example, in CSharp one typically uses:
IntPtr hBitmap = (IntPtr)rr_connection.GetBitmap("processed");
if (hBitmap.ToInt32() != 0)
{
if (bmpToDisplay != null) bmpToDisplay.Dispose();
bmpToDisplay = Image.FromHbitmap(hBitmap);
DeleteObject(hBitmap);
}
to grab an image that can then be used within CSharp (from CSharp example).
STeven.
|
|
|
Adas L [7 posts] |
8 year
|
Hi
Yes, my fault, I was just tired, and posted something which didn't allow any reasonable answer, as there were no code.
I'm using C# wrapper.
var roborealm = new API_WrapperClass();
int d = roborealm.GetImage("processed", out image, out width, out height, "jpeg");
GetImage() is returning some value, is outing width and height but image (byte[]) is of lenght 0.
Annoying thing is that it's working in some of exemples provided by roborealm but not in all of them and not in my code.
Workaround which I found is to use:
roborealm.SaveImage("processed", "filepath/fileneame")
and read it from disk.
This works but it's obviously very hackish way to do it.
Lot of thanks for your interest.
|
|
|
Adas L [7 posts] |
8 year
|
Errata:
It's not of length zero, it's null
Width and height are correct and are 640x480
d is variable from about 6k to 25k, what does makes sense.
|
|
|
Steven Gentner from United States [273 posts] |
8 year
|
Adas,
If you look in the API download in the CSharp folder you will see a JpegSetTest. In that code you will find
object pixels, width, height;
int numBytes = rr.GetImage("source", out pixels, out width, out height, "jpeg");
byte[] rgbArray = (byte[])pixels;
MemoryStream ms = new MemoryStream(rgbArray, 0, numBytes);
bm = new Bitmap(ms);
which works using the most recent version of RR. Can you give that project a try? The download for all API examples is
http://www.roborealm.com/downloads/API.zip
STeven.
|
|
|
Adas L [7 posts] |
8 year
|
Hi Steven
Yes, one of examples did worked. But I'm using it in Unity3D so can't copy it exactly. Working on WIndows x86 architecture.
Code goes like this:
roborealm.WaitImage();
int size = roborealm.GetImage(IMG_TYPE, out img, out width, out height, IMG_FORMAT);
byte[] image = (byte[])img;
MemoryStream stream;
try {
stream = new MemoryStream(image, 0, size);
} catch (Exception ex) {
Debug.LogError("stream creation failed: "+ex.Message);
}
size, width, length makes sense, however exception is thrown by stream ctor that argument can not be null. So there is something wrong with GetImage().
Best regards
A.
|
|
|
Steven Gentner from United States [273 posts] |
8 year
|
What is img defined as?
Most likely the function is unable to place the more complicated image structure into the img variable. If img is null it should create the variable as single array of bytes (VT_ARRAY | VT_UI1) If the variable is already initialized to an object it will check that it is a single dimensional array of bytes and fill that.
STeven.
|
|
|
Adas L [7 posts] |
8 year
|
Unfortunately that seems to not be the case.
I tried both null and new byte[64000], previously it was not initialized as out parameter usually means "I don't care what I get"
In both cases exception is thrown that stream can not be initialize with null parameter.
|
|
|
Steven Gentner from United States [273 posts] |
8 year
|
What is img defined as:
Dim img;
Object img;
Byte img;
???
STeven.
|
|
|
Adas L [7 posts] |
8 year
|
oh, sorry, it's an object, will try with byte[]
|
|
|
Adas L [7 posts] |
8 year
|
No - I can't pass there byte[],
Method parameter is object so I need to pass an object
|
|