Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.android;
00018
00019 import com.google.common.base.Preconditions;
00020
00021 import android.graphics.Bitmap;
00022 import android.graphics.Color;
00023 import org.jboss.netty.buffer.ChannelBuffer;
00024
00028 public class BitmapFromImage implements MessageCallable<Bitmap, sensor_msgs.Image> {
00029
00030 @Override
00031 public Bitmap call(sensor_msgs.Image message) {
00032 Preconditions.checkArgument(message.getEncoding().equals("rgb8"));
00033 Bitmap bitmap =
00034 Bitmap.createBitmap((int) message.getWidth(), (int) message.getHeight(),
00035 Bitmap.Config.ARGB_8888);
00036 for (int x = 0; x < message.getWidth(); x++) {
00037 for (int y = 0; y < message.getHeight(); y++) {
00038 ChannelBuffer data = message.getData();
00039 byte red = data.getByte((int) (y * message.getStep() + 3 * x));
00040 byte green = data.getByte((int) (y * message.getStep() + 3 * x + 1));
00041 byte blue = data.getByte((int) (y * message.getStep() + 3 * x + 2));
00042 bitmap.setPixel(x, y, Color.argb(255, red & 0xFF, green & 0xFF, blue & 0xFF));
00043 }
00044 }
00045 return bitmap;
00046 }
00047 }