Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Picture; public class Main { /** * @brief Converting picture to bitmap array. * * @author daiping.zhao * @param bm [IN] bitmap object * * @return Return converted bytes array */ public static Bitmap pictureToBitmap(Picture picture, int width, int height) { Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(b); // May need to tweak these values to determine what is the // best scale factor int picWidth = picture.getWidth(); int picHeight = picture.getHeight(); float scaleFactorX = 1.0f; float scaleFactorY = 1.0f; if (picWidth > 0) { scaleFactorX = (float) width / (float) picWidth; } else { return null; } if (picWidth > picHeight) { // If the device is in landscape and the page is shorter // than the height of the view, stretch the thumbnail to fill the // space. scaleFactorY = (float) height / (float) picHeight; } else { // In the portrait case, this looks nice. scaleFactorY = scaleFactorX; } canvas.scale(scaleFactorX, scaleFactorY); picture.draw(canvas); return b; } }