BitmapFromImage.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
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 }


android_core
Author(s): Damon Kohler
autogenerated on Thu Jun 6 2019 21:20:07