ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Android_tutorial_image_transport displays strange image

asked 2012-10-05 00:03:06 -0600

KazutoMurase gravatar image

updated 2012-10-08 18:22:14 -0600

Hi, I want to use a sample package of rosjava.android ,"android_tutorial_image_transport".

This package subscribes ros messages which content is compressed image data. But the android screen displays strange image because ros began to publishe BGR data from f-turtle. So, I rewrite BitmapFromCompressedImage.java in android_gingerbread_mr1 as follows to transfer BGR data to RGB data.But it takes too much time.

What should I deal with this problem?


  @Override
  public Bitmap call(sensor_msgs.CompressedImage message) {
    ChannelBuffer buffer = message.getData();
    byte[] data = buffer.array();
    Bitmap bitmap =BitmapFactory.decodeByteArray(data,buffer.arrayOffset(),buffer.readableBytes());

    final int Width = bitmap.getWidth();
    final int Height = bitmap.getHeight();
    Bitmap bitmap_output = Bitmap.createBitmap(Width, Height, Bitmap.Config.ARGB_8888);
    int[] pixels = new int[Width*Height];
    bitmap.getPixels(pixels, 0, Width, 0, 0, Width, Height);
    for(int x = 0; x < Width; x++){
        for(int y = 0; y < Height; y++){
            int pixel = pixels[x + y * Width];
            pixels[x + y * Width] = Color.rgb(Color.blue(pixel), Color.green(pixel), Color.red(pixel));
        }
    }
    bitmap_output.setPixels(pixels, 0, Width, 0, 0, Width, Height);                                            
    return bitmap_output;
    //return BitmapFactory.decodeByteArray(data, buffer.arrayOffset(), buffer.readableBytes());                                                                
  }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-10-10 05:30:41 -0600

damonkohler gravatar image

I suggest changing your incoming image to one that the BitmapFactory supports. See http://developer.android.com/reference/android/graphics/Bitmap.Config.html

I believe you'll always run into one performance issue or another otherwise.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-10-05 00:03:06 -0600

Seen: 380 times

Last updated: Oct 10 '12