コード例 #1
0
ファイル: BitmapFromImage.java プロジェクト: bsculley/raupe
 @Override
 public Bitmap call(sensor_msgs.Image message) {
   Preconditions.checkArgument(message.getEncoding().equals("rgb8"));
   Bitmap bitmap =
       Bitmap.createBitmap(
           (int) message.getWidth(), (int) message.getHeight(), Bitmap.Config.ARGB_8888);
   for (int x = 0; x < message.getWidth(); x++) {
     for (int y = 0; y < message.getHeight(); y++) {
       ChannelBuffer data = message.getData();
       byte red = data.getByte((int) (y * message.getStep() + 3 * x));
       byte green = data.getByte((int) (y * message.getStep() + 3 * x + 1));
       byte blue = data.getByte((int) (y * message.getStep() + 3 * x + 2));
       bitmap.setPixel(x, y, Color.argb(255, red & 0xFF, green & 0xFF, blue & 0xFF));
     }
   }
   return bitmap;
 }
コード例 #2
0
  public static BufferedImage bufferedImageFromRosMessageRaw(
      ColorModel colorModel, sensor_msgs.Image imageMessage) {
    int width = imageMessage.getWidth();
    int height = imageMessage.getHeight();

    byte[] payload = imageMessage.getData().array();
    BufferedImage ret = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    DataBuffer dataBuffer =
        new DataBufferByte(payload, payload.length, imageMessage.getData().arrayOffset());
    SampleModel sampleModel = colorModel.createCompatibleSampleModel(width, height);

    WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer, null);
    ret.setData(raster);

    return ret;
  }