public static void into(RequestCreator requestCreator, Drawable placeHolder, Drawable errorDrawable, Target target) { boolean mainThread = Looper.myLooper() == Looper.getMainLooper(); if (mainThread) { requestCreator.into(target); } else { try { target.onBitmapFailed(placeHolder); Bitmap bitmap = requestCreator.get(); target.onBitmapLoaded(bitmap, Picasso.LoadedFrom.MEMORY); } catch (IOException e) { target.onBitmapFailed(errorDrawable); } } }
@Override public Bitmap loadImage(Context context, String url) { try { return Picasso.with(context).load(url).get(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override protected Bitmap loadBitmap(String src) { try { return Picasso.with(MainActivity.this) .load(src) .get(); } catch (IOException e) { throw new RuntimeException("Whoops!"); } } })
/** * Loads the request into an imageview. * If called from a background thread, the request will be performed synchronously. * @param requestCreator A request creator * @param imageView The target imageview * @param callback a Picasso callback */ public static void into(RequestCreator requestCreator, ImageView imageView, Callback callback) { boolean mainThread = Looper.myLooper() == Looper.getMainLooper(); if (mainThread) { requestCreator.into(imageView, callback); } else { try { Bitmap bitmap = requestCreator.get(); imageView.setImageBitmap(bitmap); if (callback != null) { callback.onSuccess(); } } catch (IOException e) { if (callback != null) { callback.onError(); } } } }
@Override public Bitmap loadImage(Context context, String url, int width, int height) { try { return Picasso.with(context).load(url).resize(width, height).get(); } catch (IOException e) { throw new RuntimeException(e); } } });
/** * Loads the request into an imageview. * If called from a background thread, the request will be performed synchronously. * @param requestCreator A request creator * @param imageView The target imageview * @param callback a Picasso callback */ public static void into(RequestCreator requestCreator, ImageView imageView, Callback callback) { boolean mainThread = Looper.myLooper() == Looper.getMainLooper(); if (mainThread) { requestCreator.into(imageView, callback); } else { try { Bitmap bitmap = requestCreator.get(); imageView.setImageBitmap(bitmap); if (callback != null) { callback.onSuccess(); } } catch (IOException e) { if (callback != null) { callback.onError(); } } } }
@Override protected Bitmap doInBackground(String... params) { Bitmap b = null; Context c = context.get(); if (c == null) return null; try { b = Picasso.get().load(params[0]).get(); FileOutputStream out = new FileOutputStream(f); b.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return b; }
private Result<Bitmap> loadImage() { Bitmap bitmap = null; try { bitmap = Picasso.with(AppAgera.getAppContext()).load(mUri).get(); } catch (IOException e) { e.printStackTrace(); } return absentIfNull(bitmap); }
@Override public void run() { try { final Bitmap b = Picasso.with(MainActivity.this).load(imageUrl).get(); runOnUiThread(new Runnable() { @Override public void run() { // tiv.setImage(b); TransitionalImage transitionalImage = new TransitionalImage.Builder() .duration(500) .backgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorAccent)) //.image(R.drawable.sample_image) .image(b) .create(); tiv.setTransitionalImage(transitionalImage); } }); } catch (IOException e) {e.printStackTrace();} } });
@Override public void run() { try{ final Bitmap bitmap = Picasso.with(mContext).load(shoe.getImageUrl()).get(); ((Activity) mContext).runOnUiThread(new Runnable() { @Override public void run() { TransitionalImage transitionalImage = new TransitionalImage.Builder() .duration(500) /*.backgroundColor(ContextCompat.getColor(, R.color.colorAccent))*/ /*.image(R.drawable.sample_image)*/ .image(bitmap) .create(); holder.image.setTransitionalImage(transitionalImage); bitmap.recycle(); } }); } catch (IOException e){e.printStackTrace();} } });
@Override public void run() { final List<Bitmap> bitmapList = new ArrayList<>(); for (String decodePic : avatarList) { try { //生成bitmap对象 Bitmap b = Picasso.with(MainActivity.this).load(decodePic).get(); if(b != null) { bitmapList.add(b); } } catch (IOException e) { e.printStackTrace(); } } final Bitmap result = AvatarUtils.getAvatar(bitmapList, 200, 200); MainActivity.this.runOnUiThread(new Runnable() { @Override public void run() { iv_item_avatar.setImageBitmap(bitmapList.size() == 1 ? bitmapList.get(0) : result); } }); } }).start();
@Override protected Boolean doInBackground(Void... voids) { Bitmap bitmap = null; try { bitmap = Picasso.get().load(url).get(); } catch (IOException e) { e.printStackTrace(); return false; } // Save image to gallery String savedImageURL = MediaStore.Images.Media.insertImage( getContentResolver(), bitmap, "IMAGE_" + System.currentTimeMillis(), null ); Log.d("===", "saved " + savedImageURL); return true; }
@Override public void handleMessage(Message msg) { // 工作线程做耗时下载 String url = (String) msg.obj; Bitmap bitmap = null; try { bitmap = Picasso.with(getApplicationContext()).load(url).get(); Intent intent = new Intent(); intent.putExtra("bitmap",bitmap); intent.setAction(RECEIVER_ACTION); // 通知显示 LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); } catch (IOException e) { e.printStackTrace(); } //工作完成之后,停止服务 stopSelf(); } }
Bitmap b = Picasso.with(context).load(Utilities.getFaviconUrl(bookmark.getKey())).get(); remoteViews.setImageViewBitmap(R.id.imageview_favicon, b); } catch (IOException e) {
private Notification buildNotification(Playlist playlist) { Bitmap image = null; if (playlist.images.size() > 0) { try { image = Picasso.with(getApplicationContext()) .load(playlist.images.get(0).url) .resize(CARD_WIDTH, CARD_HEIGHT) .centerCrop() .get(); } catch (IOException e) { e.printStackTrace(); } } return new NotificationCompat.BigPictureStyle( new NotificationCompat.Builder(getApplicationContext()) .setContentTitle(playlist.name) .setContentText(playlist.description) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setLocalOnly(true) .setOngoing(true) .setColor(getResources().getColor(R.color.fastlane_background)) .setCategory(Notification.CATEGORY_RECOMMENDATION) .setLargeIcon(image) .setSmallIcon(R.drawable.ic_launcher) .setContentIntent(buildPendingIntent(playlist.id, playlist.uri)) .setExtras(null)) .build(); }
public void updateNowPlayingMetadata(Track track) { MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder(); // track title metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, track.name); // artists metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, Utils.getTrackArtists(track)); // album picture try { Bitmap bitmap = Picasso.with(SpotifyTvApplication.getInstance().getApplicationContext()) .load(track.album.images.get(0).url) .get(); metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap); } catch (IOException e) { Timber.e(e, "Error downloading track picture for now playing card"); } mNowPlayingSession.setMetadata(metadataBuilder.build()); } }
new Thread(() -> { try { Bitmap bmp = Picasso.get().load(url).get(); mContext.runOnUiThread(() -> { if(isAdded()){