Skip to content Skip to sidebar Skip to footer

How To Set An Image In Android App With Sftp Input Stream?

I'm using Android Studio to build an application. In this app, I want to get an image in a specific folder from a linux host using Jsch sftp, and set this new picture to an already

Solution 1:

First declare ddd just after:

new AsyncTask<Integer, Void, Void>(){

so:

new AsyncTask<Integer, Void, Void>(){

        Drawable ddd = null;

        @Override
        protectedVoid doInBackground(Integer... params) {

Then in doInBackround change the line:

Drawableddd= Drawable.createFromStream(bis,"ddd");

to:

ddd = Drawable.createFromStream(bis,"ddd");

and finally move iv1.setImageDrawable(ddd); inside of onPostExecute of your AsyncTask (you must override it like you have done for doInBackground):

@OverrideprotectedvoidonPostExecute(Void unused) {
    iv1.setImageDrawable(ddd);
}

Solution 2:

Use the following method to convert imageView drawable to input stream

voidgetInputStreamFromImageView(ImageView imageView) {
    Bitmapbitmap= ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    ByteArrayOutputStreambos=newByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 0/*ignored for PNG*/, bos);
    byte[] bitmapdata = bos.toByteArray();
    ByteArrayInputStreambs=newByteArrayInputStream(bitmapdata);
}

Post a Comment for "How To Set An Image In Android App With Sftp Input Stream?"