List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
private BitmapDrawable(BitmapState state, Resources res)
From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java
private void prepareGenerateSourceImages() { mImageFillPaint.setColor(Color.WHITE); mImageFillPaint.setAntiAlias(true);/*from w ww . j a va2 s .c om*/ mAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); mSelectedSourceImage = new BitmapDrawable(getResources(), generateSourceImage( ResourcesCompat.getDrawable(getResources(), R.drawable.ic_source_selected, null))); }
From source file:com.ifeng.util.imagecache.ImageWorker.java
/** * ??ImageViewBitmapUri/* w w w. ja v a 2 s . c om*/ * * @param item * The loadtask of the image to download. * @param callback * The BitmapWorkCallbackTaskContainer to sync with the bitmap. * @see ImageFilepathCallback * @see ImageBitmapCallback */ final protected void loadImageInternal(BitmapTaskItem item, BitmapWorkCallbackTaskContainer callback) { if (item == null || item.mDataSource == null || callback == null) { return; } // ? if (item.mDataSource instanceof String && TextUtils.isEmpty((CharSequence) item.mDataSource)) { return; } // resId?s if (item.mDataSource instanceof Integer && (Integer) item.mDataSource == 0) { return; } BitmapDrawable value = null; if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(item.mDataSource)); } else if (callback instanceof ImageFilepathCallback) { Log.e(TAG, "ImageFilepathCallback need a ImageCache to get the image filepath."); return; } if (value != null && callback instanceof ImageWorkerDrawableCallback) { // Bitmap found in memory cache // Bug fix by XuWei 2013-09-09 // Drawable?bug?ViewDrawable??Drawable Drawable copyDrawable = new BitmapDrawable(mResources, value.getBitmap()); ((ImageWorkerDrawableCallback) callback).getImageDrawable(copyDrawable); } else if (cancelPotentialWork(item.mDataSource, callback)) { final BitmapWorkerCallbackTask task = new BitmapWorkerCallbackTask(callback); callback.setBitmapWorkerCallbackTask(task); // NOTE: This uses a custom version of AsyncTask that has been // pulled from the // framework and slightly modified. Refer to the docs at the top of // the class // for more info on what was changed. task.executeOnExecutor(mExecutor, item); } }
From source file:com.android.ex.chips.RecipientEditTextView.java
private DrawableRecipientChip constructChipSpan(final RecipientEntry contact, final boolean pressed, final boolean leaveIconSpace) throws NullPointerException { if (mChipBackground == null) throw new NullPointerException("Unable to render any chips as setChipDimensions was not called."); final TextPaint paint = getPaint(); final float defaultSize = paint.getTextSize(); final int defaultColor = paint.getColor(); Bitmap tmpBitmap;/*from www. j a v a2s. c om*/ if (pressed) tmpBitmap = createSelectedChip(contact, paint); else tmpBitmap = createUnselectedChip(contact, paint, leaveIconSpace); // Pass the full text, un-ellipsized, to the chip. final Drawable result = new BitmapDrawable(getResources(), tmpBitmap); result.setBounds(0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight()); final DrawableRecipientChip recipientChip = new VisibleRecipientChip(result, contact); // Return text to the original size. paint.setTextSize(defaultSize); paint.setColor(defaultColor); return recipientChip; }
From source file:com.android.launcher3.Utilities.java
/** * Returns a bitmap which is of the appropriate size to be displayed as an icon *///from w w w . jav a 2s. c o m public static Bitmap createIconBitmap(Bitmap icon, Context context) { final int iconBitmapSize = getIconBitmapSize(); if (iconBitmapSize == icon.getWidth() && iconBitmapSize == icon.getHeight()) { return icon; } return createIconBitmap(new BitmapDrawable(context.getResources(), icon), context); }
From source file:com.example.app_2.activities.ImageGridActivity.java
private void setActionBarTitleFromCategoryId(Long category_id) { Uri uri = Uri.parse(ImageContract.CONTENT_URI + "/" + category_id); Cursor c = getApplicationContext().getContentResolver().query(uri, new String[] { ImageContract.Columns.FILENAME, ImageContract.Columns.DESC }, null, null, null); if (c != null) { c.moveToFirst();/* ww w . j a v a2 s . com*/ if (!c.isAfterLast()) { mActionBar.setTitle(c.getString(1)); String path = Storage.getPathToScaledBitmap(c.getString(0), 50); Bitmap user_icon = ScalingUtilities.decodeFile(path, 50, 50, ScalingLogic.FIT); mActionBar.setIcon(new BitmapDrawable(getResources(), user_icon)); } c.close(); } }
From source file:cl.ipp.katbag.fragment.Player.java
@SuppressWarnings("deprecation") public void setPictureBackground(String type_world, int scaleFactor, long id_world) { // Get the dimensions of the View int targetW = playerView.getWidth(); int targetH = playerView.getHeight(); // Get the dimensions of the bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image if (scaleFactor == -1) { if (photoW != 0 && targetW != 0 && photoH != 0 && targetH != 0) scaleFactor = Math.min(photoW / targetW, photoH / targetH); else//from w w w . j a v a 2 s . c o m scaleFactor = 1; mainActivity.katbagHandler.updateWorld(id_world, type_world, mCurrentPhotoPath, scaleFactor); } // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true; Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); try { bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath); } catch (OutOfMemoryError e2) { e2.printStackTrace(); // handle gracefully. } } BitmapDrawable background = new BitmapDrawable(mainActivity.context.getResources(), bitmap); playerView.setBackgroundDrawable(background); }
From source file:com.appunite.scroll.ScaleImageView.java
/** * Set image drawable//from ww w.j a v a2 s .co m * @param bitmap set image to display */ @SuppressWarnings("UnusedDeclaration") public void setSrcBitmap(Bitmap bitmap) { if (bitmap == null) { setSrcDrawable(null); return; } final Resources resources = getResources(); assert resources != null; setSrcDrawable(new BitmapDrawable(resources, bitmap)); }
From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java
private void setPictureSelected() { if (!new File(mUriSavedFile.getPath()).exists()) { UIUtils.showLongToast(mActivity, mActivity.getString(R.string.error_please_try_again)); return;/*from w w w .j a v a 2 s . c o m*/ } IOUtils.compressPicture(mUriSavedFile, 600000); mUploadFileExtenstion = AttachmentViewerActivity.CONTENT_TYPE_JPEG; BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; Bitmap bitmap = ImageHelper.getBitmapFromFile(mUriSavedFile.getPath(), options); Drawable d = new BitmapDrawable(Resources.getSystem(), bitmap); mAttachmentPreview.setImageDrawable(d); mAttachmentContainer.setVisibility(View.VISIBLE); mHasImageSelected = true; initImageButtonsNavigation(); }
From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java
private void setVideoSelected() { if (!new File(mUriSavedFile.getPath()).exists()) { UIUtils.showLongToast(mActivity, mActivity.getString(R.string.error_please_try_again)); return;/*w ww. ja v a 2s .c o m*/ } Bitmap bitmap = UIUtils.createVideoThumbnail(mActivity, mUriSavedFile.getPath(), UIUtils.convertDipToPixels(mActivity, 200)); Drawable d = new BitmapDrawable(Resources.getSystem(), bitmap); mAttachmentPreview.setImageDrawable(d); mAttachmentContainer.setVisibility(View.VISIBLE); mHasVideoSelected = true; initImageButtonsNavigation(); }
From source file:com.channelsoft.common.bitmapUtil.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView// w w w . ja v a 2s . c o m * @param bitmap */ private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if ("0".equals(imageView.getTag())) { // ?? bitmap = toGrayscale(bitmap); } if (mFadeInBitmap) { // Transition drawable with a transparent drwabale and the final bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); // Set background to loading bitmap //TODO: miaolikui delete 20121229 // imageView.setBackgroundDrawable( // new BitmapDrawable(mResources, mLoadingBitmap)); Log.d(TAG, tagStr + ":imageView.setImageDrawable:" + System.currentTimeMillis()); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { Log.d(TAG, tagStr + ":imageView.setImageBitmap:" + System.currentTimeMillis()); imageView.setImageBitmap(bitmap); } }