Decodes an InputStream to Bitmap resizing the image to be inSampleSize times smaller then the original. - Android Graphics

Android examples for Graphics:Bitmap Stream

Description

Decodes an InputStream to Bitmap resizing the image to be inSampleSize times smaller then the original.

Demo Code

/*******************************************************************************
 * Copyright 2013 AppGlu, Inc./*from  w w w  .ja va 2 s.  c  om*/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
//package com.java2s;

import java.io.InputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {
    /**
     * Decodes an InputStream to Bitmap resizing the image to be <code>inSampleSize</code> times smaller then the original.
     * @param inputStream an input stream to an image
     * @param inSampleSize how much smaller that the image will be, for example, <code>inSampleSize</code> equals 2 will return an image 1/2 the size of the original
     * @return the resized Bitmap
     */
    public static Bitmap decodeSampledBitmapFromInputStream(
            InputStream inputStream, int inSampleSize) {
        BitmapFactory.Options options = new BitmapFactory.Options();

        options.inSampleSize = inSampleSize;

        return BitmapFactory.decodeStream(inputStream, null, options);
    }
}

Related Tutorials