List of usage examples for android.widget ImageView getDrawable
public Drawable getDrawable()
From source file:Main.java
public static void unbindImageDrawables(View view) { if (null == view) { return;/*from w ww.j a v a 2 s . c o m*/ } if (view instanceof ImageView) { ImageView imageView = (ImageView) view; if (imageView.getDrawable() != null) { imageView.getDrawable().setCallback(null); imageView.setImageDrawable(null); } } if (view instanceof ViewGroup) { for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { unbindImageDrawables(((ViewGroup) view).getChildAt(i)); } } }
From source file:Main.java
public static Bitmap getBitmapFromImageView(final ImageView imageView) { return imageView == null ? null : ((BitmapDrawable) imageView.getDrawable()).getBitmap(); }
From source file:Main.java
/** * Entfernt ein zur ImageView zugeordnetes Bitmap aus dem Speicher * @param imageView ImageView welches das Bitmap anzeigt *///w w w . ja v a2 s . c o m public static void recycleBitmapFromImageView(ImageView imageView) { if (imageView != null && imageView.getDrawable() != null && imageView.getDrawable() instanceof BitmapDrawable) { final Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); recycleBitmap(bitmap); imageView.setImageBitmap(null); } }
From source file:Main.java
public static void unbindDrawables(View view) { if (null == view) { return;/*from w w w .jav a2 s . co m*/ } if (view.getBackground() != null) { view.getBackground().setCallback(null); if (Build.VERSION.SDK_INT >= 16) view.setBackground(null); else view.setBackgroundDrawable(null); } if (view instanceof ImageView) { ImageView imageView = (ImageView) view; if (imageView.getDrawable() != null) { imageView.getDrawable().setCallback(null); imageView.setImageDrawable(null); } } if (view instanceof ViewGroup) { for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { unbindDrawables(((ViewGroup) view).getChildAt(i)); } if (!(view instanceof AdapterView<?>)) { ((ViewGroup) view).removeAllViews(); } } }
From source file:Main.java
public static void unbindInvisibleImageDrawables(View view) { if (null == view) { return;//from w w w. j a v a 2 s.co m } if (view instanceof ImageView) { ImageView imageView = (ImageView) view; if (imageView.getDrawable() != null && isInVisisble(imageView)) { imageView.getDrawable().setCallback(null); imageView.setImageDrawable(null); } } if (view instanceof ViewGroup) { for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { unbindInvisibleImageDrawables(((ViewGroup) view).getChildAt(i)); } } }
From source file:Main.java
public static void recycleImageViewBitmap(ImageView imageView) { if (imageView == null) return;//from w w w . j a va2 s .c o m Drawable drawable = imageView.getDrawable(); if (drawable != null && drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; Bitmap bitmap = bitmapDrawable.getBitmap(); if (bitmap != null && !bitmap.isRecycled()) { bitmap.recycle(); } } }
From source file:Main.java
/** * release all image resource bind on view * @param view/*from ww w . j a v a 2 s . c om*/ */ @SuppressWarnings("deprecation") public static void unbindDrawables(View view) { if (null == view) { return; } if (view.getBackground() != null) { view.getBackground().setCallback(null); if (Build.VERSION.SDK_INT >= 16) view.setBackground(null); else view.setBackgroundDrawable(null); } if (view instanceof ImageView) { ImageView imageView = (ImageView) view; if (imageView.getDrawable() != null) { imageView.getDrawable().setCallback(null); imageView.setImageDrawable(null); } } if (view instanceof ViewGroup) { for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { unbindDrawables(((ViewGroup) view).getChildAt(i)); } if (!(view instanceof AdapterView<?>)) { ((ViewGroup) view).removeAllViews(); } } }
From source file:Main.java
public static void releaseImageView(ImageView imageView) { if (imageView != null) { BitmapDrawable bitmapDrawable = (BitmapDrawable) (imageView.getDrawable()); if (bitmapDrawable != null) { bitmapDrawable.setCallback(null); }// ww w. j av a 2 s . c om imageView.setImageBitmap(null); } }
From source file:Main.java
public static BitmapDrawable sizeChanger(Context context, ImageView imageView, int sizeOnDps, int orientation) { Drawable drawing = imageView.getDrawable(); if (drawing == null) { return null; }/*w ww. j av a 2 s.c o m*/ Bitmap bitmap = ((BitmapDrawable) drawing).getBitmap(); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int bounding = dpToPx(250, context); float xScale = ((float) bounding) / width; float yScale = ((float) bounding) / height; float scale = (xScale <= yScale) ? xScale : yScale; Matrix matrix = new Matrix(); matrix.postScale(scale, scale); matrix.postRotate(orientation, imageView.getDrawable().getBounds().width() / 2, imageView.getDrawable().getBounds().height() / 2); Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); width = scaledBitmap.getWidth(); height = scaledBitmap.getHeight(); return new BitmapDrawable(scaledBitmap); }
From source file:Main.java
public static Rect getBitmapRectFromImageView(ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bitmap = null;//from w ww. ja va 2s . c om if (drawable instanceof BitmapDrawable) { bitmap = ((BitmapDrawable) drawable).getBitmap(); } Rect rect = new Rect(); boolean isVisible = imageView.getGlobalVisibleRect(rect); if (!isVisible) { int[] location = new int[2]; imageView.getLocationOnScreen(location); rect.left = location[0]; rect.top = location[1]; rect.right = rect.left + imageView.getWidth(); rect.bottom = rect.top + imageView.getHeight(); } if (bitmap != null) { int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); int imageViewWidth = imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight(); int imageviewHeight = imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom(); float startScale; if ((float) imageViewWidth / bitmapWidth > (float) imageviewHeight / bitmapHeight) { // Extend start bounds horizontally startScale = (float) imageviewHeight / bitmapHeight; } else { startScale = (float) imageViewWidth / bitmapWidth; } bitmapHeight = (int) (bitmapHeight * startScale); bitmapWidth = (int) (bitmapWidth * startScale); int deltaX = (imageViewWidth - bitmapWidth) / 2; int deltaY = (imageviewHeight - bitmapHeight) / 2; rect.set(rect.left + deltaX, rect.top + deltaY, rect.right - deltaX, rect.bottom - deltaY); return rect; } else { return null; } }