Convert bitmap to Stream - Android Graphics

Android examples for Graphics:Bitmap File

Description

Convert bitmap to Stream

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class Main {

    public static InputStream bitmap2Stream(Bitmap bitmap) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG, 100, baos);
        InputStream is = new ByteArrayInputStream(baos.toByteArray());
        return is;
    }//from ww w .  j a  va 2 s.co  m
}

Related Tutorials