Android Bitmap to InputStream Convert convertToInputStream(Bitmap bitmap)

Here you can find the source of convertToInputStream(Bitmap bitmap)

Description

convert To Input Stream

Declaration

public static InputStream convertToInputStream(Bitmap bitmap) 

Method Source Code

//package com.java2s;
import android.graphics.Bitmap;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class Main {
    public static InputStream convertToInputStream(String string) {
        byte[] bytes = string.getBytes();
        return new ByteArrayInputStream(bytes);
    }//from   w ww . j ava 2s.c  om

    public static InputStream convertToInputStream(Bitmap bitmap) {
        ByteArrayOutputStream expectedOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/,
                expectedOutputStream);
        byte[] expectedBitmapData = expectedOutputStream.toByteArray();
        return new ByteArrayInputStream(expectedBitmapData);
    }
}