Example usage for android.widget ImageView setImageBitmap

List of usage examples for android.widget ImageView setImageBitmap

Introduction

In this page you can find the example usage for android.widget ImageView setImageBitmap.

Prototype

@android.view.RemotableViewMethod
public void setImageBitmap(Bitmap bm) 

Source Link

Document

Sets a Bitmap as the content of this ImageView.

Usage

From source file:com.afwsamples.testdpc.common.Util.java

public static void updateImageView(Context context, ImageView imageView, Uri uri) {
    try {//w w w .ja v  a 2 s .  c o  m
        InputStream inputStream = context.getContentResolver().openInputStream(uri);
        // Avoid decoding the entire image if the imageView holding this image is smaller.
        BitmapFactory.Options bounds = new BitmapFactory.Options();
        bounds.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(inputStream, null, bounds);
        int streamWidth = bounds.outWidth;
        int streamHeight = bounds.outHeight;
        int maxDesiredWidth = imageView.getMaxWidth();
        int maxDesiredHeight = imageView.getMaxHeight();
        int ratio = Math.max(streamWidth / maxDesiredWidth, streamHeight / maxDesiredHeight);
        if (ratio > 1) {
            bounds.inSampleSize = ratio;
        }
        bounds.inJustDecodeBounds = false;

        inputStream = context.getContentResolver().openInputStream(uri);
        imageView.setImageBitmap(BitmapFactory.decodeStream(inputStream, null, bounds));
    } catch (FileNotFoundException e) {
        Toast.makeText(context, R.string.error_opening_image_file, Toast.LENGTH_SHORT);
    }
}

From source file:com.liferay.social.task.PortraitAsyncTask.java

protected void onPostExecute(Bitmap bitmap) {
    ImageView imageView = _imageView.get();

    if (imageView != null) {
        imageView.setImageBitmap(bitmap);
    }//from   ww w  . j a v  a  2 s .  c  o m
}

From source file:com.android.volley.cache.SimpleImageLoader.java

/**
 * Sets a {@link android.graphics.Bitmap} to an {@link android.widget.ImageView} using a
 * fade-in animation. If there is a {@link android.graphics.drawable.Drawable} already set on
 * the ImageView then use that as the image to fade from. Otherwise fade in from a transparent
 * Drawable./*from w ww  .j  a v a  2 s.  com*/
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private static void setImageBitmap(final ImageView imageView, final Bitmap bitmap, Resources resources,
        boolean fadeIn) {

    // If we're fading in and on HC MR1+
    if (fadeIn && Utils.hasHoneycombMR1()) {
        // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the
        // ImageView
        imageView.animate().scaleY(0.95f).scaleX(0.95f).alpha(0f)
                .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        imageView.setImageBitmap(bitmap);
                        imageView.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME)
                                .setListener(null);
                    }
                });
    } else if (fadeIn) {
        // Otherwise use a TransitionDrawable to fade in
        Drawable initialDrawable;
        if (imageView.getDrawable() != null) {
            initialDrawable = imageView.getDrawable();
        } else {
            initialDrawable = transparentDrawable;
        }
        BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap);
        // Use TransitionDrawable to fade in
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { initialDrawable, bitmapDrawable });
        imageView.setImageDrawable(td);
        td.startTransition(Utils.ANIMATION_FADE_IN_TIME);
    } else {
        // No fade in, just set bitmap directly
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.feathercoin.wallet.feathercoin.util.BitmapFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Bitmap bitmap = (Bitmap) getArguments().getParcelable(KEY_BITMAP);

    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.bitmap_dialog);
    dialog.setCanceledOnTouchOutside(true);

    final ImageView imageView = (ImageView) dialog.findViewById(R.id.bitmap_dialog_image);
    imageView.setImageBitmap(bitmap);
    imageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(final View v) {
            dismiss();/* w  w w  .j av  a 2  s .  c  o  m*/
        }
    });

    return dialog;
}

From source file:cc.mintcoin.wallet.util.BitmapFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Bitmap bitmap = (Bitmap) getArguments().getParcelable(KEY_BITMAP);

    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.bitmap_dialog);
    dialog.setCanceledOnTouchOutside(true);

    final ImageView imageView = (ImageView) dialog.findViewById(R.id.bitmap_dialog_image);
    imageView.setImageBitmap(bitmap);
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override/*  w ww . jav a2s.  c o m*/
        public void onClick(final View v) {
            dismiss();
        }
    });

    return dialog;
}

From source file:com.bushstar.kobocoin_android_wallet.util.BitmapFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Bitmap bitmap = getArguments().getParcelable(KEY_BITMAP);

    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.bitmap_dialog);
    dialog.setCanceledOnTouchOutside(true);

    final ImageView imageView = (ImageView) dialog.findViewById(R.id.bitmap_dialog_image);
    imageView.setImageBitmap(bitmap);
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override//from   w  ww .  j av a  2  s  .  co m
        public void onClick(final View v) {
            dismiss();
        }
    });

    return dialog;
}

From source file:com.cihon.androidrestart_keven.activity.WebViewActivity.java

/**
 * @param str h5??//from w w w .  j a  va 2  s .  c  om
 */
@Override
public void imgBase64(String str, Bitmap b) {

    Log.e("Log", "webview--" + (mWebView == null));
    Log.e("Log", "webview?--" + str);
    String url = "javascript:" + "getWord('" + str + "')";
    mWebView.loadUrl(url);

    ImageView iv = (ImageView) findViewById(R.id.img);
    iv.setImageBitmap(b);

}

From source file:com.liquid.wallpapers.free.core.wallpapers.WallpaperGalleryAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Wallpaper wallpaper = this.wallpapers[position];
    ImageView imageView = new ImageView(this.context);

    try {//from   ww w. j  a  va 2  s.com
        imageView.setImageBitmap(this.wallpaperManager.getThumbImage(wallpaper));
    } catch (ClientProtocolException ex) {
        AlertDialogFactory.showErrorMessage(this.context, R.string.errorText, R.string.downloadException);
    } catch (IOException ex) {
        AlertDialogFactory.showErrorMessage(this.context, R.string.errorText, R.string.downloadException);
    }

    return imageView;
}

From source file:com.commonsware.android.bitmap.iss.BitmapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View result = inflater.inflate(R.layout.sample, container, false);
    int inSampleSize = getArguments().getInt(KEY_SAMPLE_SIZE, 1);

    try {/*from   w  w w. jav  a2 s. c o m*/
        Bitmap flower = load("Tibouchina_urvilleana_flower_ja.jpg", inSampleSize);
        Bitmap logo = load("square.png", inSampleSize);

        ImageView iv = (ImageView) result.findViewById(R.id.flower_large);

        iv.setImageBitmap(flower);
        iv = (ImageView) result.findViewById(R.id.flower_small);
        iv.setImageBitmap(flower);
        iv = (ImageView) result.findViewById(R.id.logo_large);
        iv.setImageBitmap(logo);
        iv = (ImageView) result.findViewById(R.id.logo_small);
        iv.setImageBitmap(logo);

        TextView tv = (TextView) result.findViewById(R.id.byte_count);

        tv.setText(String.valueOf(byteCount(flower)));
    } catch (IOException e) {
        Log.e(getClass().getSimpleName(), "Exception loading bitmap", e);
    }

    return (result);
}

From source file:co.mike.apptemplate.Utils.ServerUtils.RESTCient.java

public static void loadWebImage(final ImageView imgNetwork, String URL, Context context) {
    //final String URL = "http://i.imgur.com/LrwApXg.png";

    // Using Picasso...
    //Picasso.with(this).load(URL).placeholder(R.drawable.default_avatar).error(R.drawable.grumpy_cat).transform(new PicassoRoundTransform()).into(imgNetwork);

    // Using Glide...
    //Glide.with(this).load(URL).placeholder(R.drawable.default_avatar).error(R.drawable.grumpy_cat).into(imgNetwork);

    // Using ION...
    Ion.with(context).load(URL)// w w w  .j a  v a 2  s .  c om

            .asBitmap()

            .setCallback(new FutureCallback<Bitmap>() {
                @Override
                public void onCompleted(Exception e, Bitmap result) {
                    if (e == null) {
                        // Success
                        imgNetwork.setImageBitmap(result);
                    } else {
                        Log.e(TAG, "error downnload CAR URL");
                        imgNetwork.setImageResource(R.drawable.ic_launcher);
                    }
                }
            });
}