Create sensor_msgs.Image in Android
Hello all.
I'm trying to implement an application in Android. What Android needs to do is take a photo, and publish it. My problem is to convert the information for type sensor_msgs.Image. The information is in a Bitmap.
I'm trying to convert this:
public void updateMessage(Bitmap object_data){
Image image = node.getTopicMessageFactory().newFromType(Image._TYPE);
image.setHeight(object_data.getHeight());
image.setWidth(object_data.getWidth());
image.setStep(object_data.getRowBytes());
image.setEncoding("rgb8");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
object_data.compress(Bitmap.CompressFormat.PNG, 100, stream);
image.setData(ChannelBuffers.copiedBuffer(stream.toByteArray()));
msg = image;
}
For now the Header is not necessary. The problem is in the setData method of sensor_msgs.Image:
06-20 12:40:04.869: E/AndroidRuntime(9550): FATAL EXCEPTION: main
06-20 12:40:04.869: E/AndroidRuntime(9550): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=102, result=-1, data=Intent { (has extras) }} to activity {org.ros.android.android_tutorial_pubsub/org.ros.android.android_tutorial_pubsub.RaceMain}: java.lang.IllegalArgumentException
06-20 12:40:04.869: E/AndroidRuntime(9550): at android.app.ActivityThread.deliverResults(ActivityThread.java:3182)
06-20 12:40:04.869: E/AndroidRuntime(9550): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3225)
06-20 12:40:04.869: E/AndroidRuntime(9550): at android.app.ActivityThread.access$1100(ActivityThread.java:140)
06-20 12:40:04.869: E/AndroidRuntime(9550): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
06-20 12:40:04.869: E/AndroidRuntime(9550): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 12:40:04.869: E/AndroidRuntime(9550): at android.os.Looper.loop(Looper.java:137)
06-20 12:40:04.869: E/AndroidRuntime(9550): at android.app.ActivityThread.main(ActivityThread.java:4898)
06-20 12:40:04.869: E/AndroidRuntime(9550): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 12:40:04.869: E/AndroidRuntime(9550): at java.lang.reflect.Method.invoke(Method.java:511)
06-20 12:40:04.869: E/AndroidRuntime(9550): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
06-20 12:40:04.869: E/AndroidRuntime(9550): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
06-20 12:40:04.869: E/AndroidRuntime(9550): at dalvik.system.NativeStart.main(Native Method)
06-20 12:40:04.869: E/AndroidRuntime(9550): Caused by: java.lang.IllegalArgumentException
06-20 12:40:04.869: E/AndroidRuntime(9550): at com.google.common.base.Preconditions.checkArgument(Preconditions.java:76)
06-20 12:40:04.869: E/AndroidRuntime(9550): at org.ros.internal.message.field.ChannelBufferField.setValue(ChannelBufferField.java:55)
06-20 12:40:04.869: E/AndroidRuntime(9550): at org.ros.internal.message.MessageProxyInvocationHandler.invoke(MessageProxyInvocationHandler.java:46)
06-20 12:40:04.869: E/AndroidRuntime(9550): at org.ros.internal.message.$Proxy3.setData(Native Method)
06-20 12:40:04.869: E/AndroidRuntime(9550): at org.ros.android.android_tutorial_pubsub.services.ImagePublisher.updateMessage(ImagePublisher.java:70)
06-20 12:40:04.869: E/AndroidRuntime(9550): at org.ros.android.android_tutorial_pubsub.RaceMain.onActivityResult(RaceMain.java:178)
06-20 12:40:04.869: E/AndroidRuntime(9550): at android.app.Activity.dispatchActivityResult(Activity.java:5390)
06-20 12:40:04 ...