List of usage examples for android.graphics.drawable BitmapDrawable getBitmap
public final Bitmap getBitmap()
From source file:de.mrapp.android.util.BitmapUtil.java
/** * Creates and returns a bitmap from a specific drawable. * * @param drawable//from w w w . j a va 2 s. c o m * The drawable, which should be converted, as an instance of the class {@link * Drawable}. The drawable may not be null * @return The bitmap, which has been created, as an instance of the class {@link Bitmap} */ public static Bitmap drawableToBitmap(@NonNull final Drawable drawable) { ensureNotNull(drawable, "The drawable may not be null"); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; if (bitmapDrawable.getBitmap() != null) { return bitmapDrawable.getBitmap(); } } Bitmap bitmap; if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
From source file:com.cw.litenote.util.video.UtilVideo.java
public static void setVideoViewDimensions(BitmapDrawable bitmapDrawable) { int screenHeight = UtilImage.getScreenHeight(mAct); int screenWidth = UtilImage.getScreenWidth(mAct); // System.out.println("UtilVideo / _setVideoViewDimensions / screenHeight = " + screenHeight + ", screenWidth = " + screenWidth); int bitmapHeight = 0, bitmapWidth = 0; int config_orientation = mAct.getResources().getConfiguration().orientation; Bitmap bitmap = bitmapDrawable.getBitmap(); boolean bitmapIsLandScape = false; boolean bitmapIsPortrait = false; if (bitmap != null) { bitmapHeight = bitmap.getHeight(); bitmapWidth = bitmap.getWidth(); System.out.println("UtilVideo / _setVideoViewDimensions / bitmapHeight = " + bitmapHeight + ", bitmapWidth = " + bitmapWidth); bitmapIsLandScape = (bitmapWidth > bitmapHeight) ? true : false; bitmapIsPortrait = (bitmapHeight > bitmapWidth) ? true : false; // System.out.println("UtilVideo / _setVideoViewDimensions / bitmapIsLandScape 1 = " + bitmapIsLandScape); // System.out.println("UtilVideo / _setVideoViewDimensions / bitmapIsPortrait 1 = " + bitmapIsPortrait); } else {//from www .ja v a2s.co m // for remote video which there is no way to get bitmap yet // default dimension bitmapWidth = screenWidth; bitmapHeight = screenHeight / 2; // default orientation is landscape AsyncTaskVideoBitmapPager.mRotationStr = "0"; // } String rotDeg = AsyncTaskVideoBitmapPager.mRotationStr; if (rotDeg != null) { System.out.println("UtilVideo / _setVideoViewDimensions / rotDeg = " + rotDeg); if (rotDeg.equalsIgnoreCase("0")) { bitmapIsLandScape = true; bitmapIsPortrait = false; } else if (rotDeg.equalsIgnoreCase("90")) { bitmapIsLandScape = false; bitmapIsPortrait = true; } } // System.out.println("UtilVideo / _setVideoViewDimensions / bitmapIsLandScape 2 = " + bitmapIsLandScape); // System.out.println("UtilVideo / _setVideoViewDimensions / bitmapIsPortrait 2 = " + bitmapIsPortrait); int dimWidth = 0; int dimHeight = 0; // for landscape screen if (config_orientation == Configuration.ORIENTATION_LANDSCAPE) { // for landscape bitmap if (bitmapIsLandScape) { System.out.println("UtilVideo / _setVideoViewDimensions / L_scr L_bmp"); dimWidth = screenWidth; dimHeight = screenHeight; } // for portrait bitmap else if (bitmapIsPortrait) { System.out.println("UtilVideo / _setVideoViewDimensions / L_scr P_bmp"); // set screen height to be constant, and set screen width by proportional int propotionalWidth = 0; if (bitmap != null) { propotionalWidth = (bitmapWidth > bitmapHeight) ? Math.round(screenHeight * bitmapHeight / bitmapWidth) : Math.round(screenHeight * bitmapWidth / bitmapHeight); } else propotionalWidth = Math.round(screenHeight * screenHeight / screenWidth); dimWidth = propotionalWidth; dimHeight = screenHeight; } } // for portrait screen else if (config_orientation == Configuration.ORIENTATION_PORTRAIT) { // for landscape bitmap if (bitmapIsLandScape) { System.out.println("UtilVideo / _setVideoViewDimensions / P_scr L_bmp"); // set screen width to be constant, and set screen height by proportional int propotiaonalHeight = 0; if (bitmap != null) { propotiaonalHeight = (bitmapWidth > bitmapHeight) ? Math.round(screenWidth * bitmapHeight / bitmapWidth) : Math.round(screenWidth * bitmapWidth / bitmapHeight); } else propotiaonalHeight = Math.round(screenWidth * screenWidth / screenHeight); dimWidth = screenWidth; dimHeight = propotiaonalHeight; } // for portrait bitmap else if (bitmapIsPortrait) { System.out.println("UtilVideo / _setVideoViewDimensions / P_scr P_bmp"); dimWidth = screenWidth; dimHeight = screenHeight; } } // set dimensions if (UtilVideo.mVideoView != null) { UtilVideo.mVideoView.setDimensions(dimWidth, dimHeight); UtilVideo.mVideoView.getHolder().setFixedSize(dimWidth, dimHeight); System.out.println("UtilVideo / _setVideoViewDimensions / dim Width = " + dimWidth + ", dim Height = " + dimHeight); } }
From source file:de.luhmer.owncloudnewsreader.helper.BitmapDrawableLruCache.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override/*from w w w . ja v a 2s .c o m*/ protected int sizeOf(Long key, BitmapDrawable bitmap) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR1) return bitmap.getBitmap().getByteCount() / 1024; else return bitmap.getBitmap().getRowBytes() * bitmap.getBitmap().getHeight() / 1024; }
From source file:net.line2soft.preambul.views.ImageDetailFragment.java
@Override public void onStop() { BitmapDrawable img = ((BitmapDrawable) mImageView.getDrawable()); img.getBitmap().recycle(); img = null;/* w w w . j a v a 2 s .c o m*/ super.onDestroy(); }
From source file:org.jitsi.android.gui.util.DrawableCache.java
/** * Creates new instance of <tt>DrawableCache</tt>. *///from w w w . j a v a 2 s.co m public DrawableCache() { // Get max available VM memory, exceeding this amount will throw an // OutOfMemory exception. Stored in kilobytes as LruCache takes an // int in its constructor. final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/8th of the available memory for this memory cache. final int cacheSize = maxMemory / 8; cache = new LruCache<String, BitmapDrawable>(cacheSize) { @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override protected int sizeOf(String key, BitmapDrawable value) { Bitmap bmp = value.getBitmap(); int byteSize; if (AndroidUtils.hasAPI(Build.VERSION_CODES.HONEYCOMB_MR1)) { byteSize = bmp.getByteCount(); } else { byteSize = bmp.getRowBytes() * bmp.getHeight(); } return byteSize / 1024; } }; }
From source file:jp.mydns.sys1yagi.android.printingframeworksample.image.ImagePrintActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_print); findViewById(R.id.print_button).setOnClickListener(new OnClickListener() { @Override//from ww w . j a va2 s . co m public void onClick(View v) { ImageView imageView = (ImageView) findViewById(R.id.image); BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); printImage("kitkat.pdf", drawable.getBitmap()); } }); }
From source file:com.atwal.wakeup.battery.util.Utilities.java
public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { BitmapDrawable bd = (BitmapDrawable) drawable; return bd.getBitmap(); }/*from w w w . j av a 2 s . co m*/ int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, w, h); drawable.draw(canvas); return bitmap; }
From source file:poisondog.android.image.ImageCache.java
public Bitmap getBitmapFromCache(String key) throws FileSystemException { BitmapDrawable bitmap = getBitmapFromMemCache(key); if (bitmap != null) return bitmap.getBitmap(); return getBitmapFromDiskCache(key); }
From source file:com.jesjimher.bicipalma.MapaActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mapa);/*from w w w .j a v a 2 s .c o m*/ // Activar zoom GoogleMap mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapfragment)) .getMap(); // mapa.setBuiltInZoomControls(true); mapa.setMyLocationEnabled(true); // Si el mapa no est en Palma o similar, ponerlo en pza espaa CameraPosition c = mapa.getCameraPosition(); Location actual = new Location(""); actual.setLatitude(c.target.latitude); actual.setLongitude(c.target.longitude); Location pe = new Location(""); pe.setLatitude(PZAESPANYA.latitude); pe.setLongitude(PZAESPANYA.longitude); if (actual.distanceTo(pe) >= 5000) mapa.moveCamera(CameraUpdateFactory.newLatLng(PZAESPANYA)); Intent i = getIntent(); // GeoPoint point=null; if (i.hasExtra("estaciones")) { estaciones = i.getExtras().getParcelableArrayList("estaciones"); for (Estacion e : estaciones) { LevelListDrawable d = (LevelListDrawable) getResources().getDrawable(R.drawable.estado_variable); d.setLevel(e.getBicisLibres() + 1); BitmapDrawable bd = (BitmapDrawable) d.getCurrent(); Bitmap b = bd.getBitmap(); Bitmap petit = Bitmap.createScaledBitmap(b, b.getWidth() / 2, b.getHeight() / 2, false); String mensaje = String.format("%s: %d, %s: %d", getResources().getString(R.string.lbicislibres), e.getBicisLibres(), getResources().getString(R.string.lanclajeslibres), e.getAnclajesLibres()); mapa.addMarker(new MarkerOptions() .position(new LatLng(e.getLoc().getLatitude(), e.getLoc().getLongitude())) .title(e.getNombre()).snippet(mensaje).icon(BitmapDescriptorFactory.fromBitmap(petit))); } Double lat = i.getExtras().getDouble("latcentro"); Double lon = i.getExtras().getDouble("longcentro"); mapa.moveCamera(CameraUpdateFactory.zoomTo(16)); mapa.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lon))); } }
From source file:com.linkbubble.ui.ContentViewButton.java
public void setImageDrawable(Drawable drawable) { if (drawable instanceof BitmapDrawable) { int maxIconSize = getMaxIconSize(); BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; int width = bitmapDrawable.getBitmap().getWidth(); int height = bitmapDrawable.getBitmap().getHeight(); if (width > 0 && height > 0 && (width > maxIconSize || height > maxIconSize)) { int newHeight; int newWidth; if (width > height) { newWidth = maxIconSize;//from ww w . j a va 2s .c om newHeight = (int) ((float) (height / width) * maxIconSize); } else if (width < height) { newHeight = maxIconSize; newWidth = (int) ((float) (width / height) * maxIconSize); if (0 == newWidth) { newWidth = newHeight; } } else { newWidth = newHeight = maxIconSize; } // Potential fix for user exceptions below saying that width and height must be > 0 newWidth = Math.max(1, newWidth); newHeight = Math.max(1, newHeight); try { Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmapDrawable.getBitmap(), newWidth, newHeight, true); drawable = new BitmapDrawable(getResources(), resizedBitmap); } catch (java.lang.OutOfMemoryError ex) { } } } mImageView.setImageDrawable(drawable); }