List of usage examples for android.graphics Bitmap getConfig
public final Config getConfig()
From source file:com.waz.zclient.pages.main.drawing.DrawingFragment.java
private void drawSketchEditText() { if (sketchEditTextView.getVisibility() == View.VISIBLE) { sketchEditTextView.setAlpha(TEXT_ALPHA_VISIBLE); sketchEditTextView.setCursorVisible(false); //This has to be on a post otherwise the setAlpha and setCursor won't be noticeable in the drawing cache getView().post(new Runnable() { @Override/*w w w . jav a2s . co m*/ public void run() { sketchEditTextView.setDrawingCacheEnabled(true); Bitmap bitmapDrawingCache = sketchEditTextView.getDrawingCache(); if (bitmapDrawingCache != null) { FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) sketchEditTextView .getLayoutParams(); drawingCanvasView.showText(); drawingCanvasView.drawTextBitmap( bitmapDrawingCache.copy(bitmapDrawingCache.getConfig(), true), params.leftMargin, params.topMargin, sketchEditTextView.getText().toString(), sketchEditTextView.getSketchScale()); } else { drawingCanvasView.drawTextBitmap(null, 0, 0, "", 1.0f); } sketchEditTextView.setDrawingCacheEnabled(false); sketchEditTextView.setAlpha(TEXT_ALPHA_INVISIBLE); } }); } }
From source file:com.android.launcher3.Utilities.java
private static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp2.getWidth(), bmp2.getHeight(), bmp1.getConfig()); float left = (bmp2.getWidth() - (bmp1.getWidth() * ((float) bmp2.getHeight() / (float) bmp1.getHeight()))) / (float) 2.0; float bmp1newW = bmp1.getWidth() * ((float) bmp2.getHeight() / (float) bmp1.getHeight()); Bitmap bmp1new = Utils.getResizedBitmap(bmp1, bmp2.getHeight(), (int) bmp1newW); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1new, left, 0, null); canvas.drawBitmap(bmp2, new Matrix(), null); return bmOverlay; }
From source file:com.mylikes.likes.etchasketch.Slate.java
public Bitmap copyBitmap(boolean withBackground) { Bitmap newb = null;// ww w .j a v a 2 s.c o m Bitmap b = getBitmap(); if (b != null) { newb = Bitmap.createBitmap(b.getWidth(), b.getHeight(), b.getConfig()); } if (newb != null) { Canvas newc = new Canvas(newb); if (mBackgroundColor != Color.TRANSPARENT && withBackground) { newc.drawColor(mBackgroundColor); } newc.drawBitmap(b, 0, 0, null); } return newb; }
From source file:uk.co.pjmobile.mobile_apps.page_turner_reader.ReadingActivity.java
private Bitmap getBookViewSnapshot() { bookView.layout(0, 0, viewSwitcher.getWidth(), viewSwitcher.getHeight()); try {//from ww w . j a v a 2 s .c o m bookView.buildDrawingCache(false); Bitmap drawingCache = bookView.getDrawingCache(); if (drawingCache != null) { Bitmap copy = drawingCache.copy(drawingCache.getConfig(), false); bookView.destroyDrawingCache(); return copy; } } catch (OutOfMemoryError out) { viewSwitcher.setBackgroundColor(config.getBackgroundColor()); } return null; }
From source file:org.videolan.vlc.audio.AudioService.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateRemoteControlClientMetadata() { if (!LibVlcUtil.isICSOrLater()) // NOP check return;// www .j a v a2 s . c o m Media media = getCurrentMedia(); if (mRemoteControlClient != null && media != null) { MetadataEditor editor = mRemoteControlClient.editMetadata(true); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre()); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle()); editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength()); // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap. Bitmap cover = getCover(); editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, ((cover != null) ? cover.copy(cover.getConfig(), false) : null)); editor.apply(); } }
From source file:org.videolan.vlc2.audio.AudioService.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateRemoteControlClientMetadata() { if (!LibVlcUtil.isICSOrLater()) // NOP check return;//from w ww . j a va2 s. c o m Media media = getCurrentMedia(); if (mRemoteControlClient != null && media != null) { MetadataEditor editor = mRemoteControlClient.editMetadata(true); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, media.getArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre()); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle()); editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength()); // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap. Bitmap cover = getCover(); editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, ((cover != null) ? cover.copy(cover.getConfig(), false) : null)); editor.apply(); } }
From source file:org.videolan.vlc.PlaybackService.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateRemoteControlClientMetadata() { if (!AndroidUtil.isICSOrLater()) // NOP check return;/* ww w . j a va 2s . c om*/ MediaWrapper media = getCurrentMedia(); if (mRemoteControlClient != null && media != null) { MetadataEditor editor = mRemoteControlClient.editMetadata(true); if (media.getNowPlaying() != null) { editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, ""); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, ""); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, media.getNowPlaying()); } else { editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, ""); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, Util.getMediaAlbum(this, media)); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, Util.getMediaArtist(this, media)); } editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, Util.getMediaGenre(this, media)); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle()); editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength()); // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap. Bitmap cover = AudioUtil.getCover(this, media, 512); if (cover != null && cover.getConfig() != null) //In case of format not supported editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, (cover.copy(cover.getConfig(), false))); editor.apply(); } //Send metadata to Pebble watch if (media != null && mPebbleEnabled) { final Intent i = new Intent("com.getpebble.action.NOW_PLAYING"); i.putExtra("artist", Util.getMediaArtist(this, media)); i.putExtra("album", Util.getMediaAlbum(this, media)); i.putExtra("track", media.getTitle()); sendBroadcast(i); } }
From source file:com.malin.rxjava.activity.MainActivity.java
/** * ,??:?//from w ww . ja v a 2 s. c o m * CanvasBitmap? * * @param bitmap:?Bitamp * @param mCounter:0 */ //?: //1:???Bitmap //2:BitmapBitmap,Bitmap?Canvas??. //3:???(64px*64px) //4:??Bitmap??,???,???,?? //5:Bitmap?? private void createSingleImageFromMultipleImages(Bitmap bitmap, int mCounter) { if (mCounter == 0) { //1:???Bitmap mManyBitmapSuperposition = Bitmap.createBitmap(DeviceInfo.screenWidthForPortrait, DeviceInfo.screenHeightForPortrait, bitmap.getConfig()); //2:BitmapBitmap mCanvas = new Canvas(mManyBitmapSuperposition); } if (mCanvas != null) { int left;//?? int top;//?? //3:???(64px*64px) int imageWidth = Constant.IMAGE_WITH; int imageHeight = Constant.IMAGE_HEIGHT; int number = DeviceInfo.screenHeightForPortrait / imageHeight;//??,? //4:??Bitmap??,???,???,?? if (mCounter >= (mCounter / number) * number && mCounter < (((mCounter / number) + 1) * number)) {//[0,number) left = (mCounter / number) * imageWidth; top = (mCounter % number) * imageHeight; // Log.d(TAG,""+mCounter+" left="+left+" top="+top); //5:Bitmap?? mCanvas.drawBitmap(bitmap, left, top, null); } } }
From source file:com.dzt.musicplay.player.AudioService.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateRemoteControlClientMetadata() { if (!LibVlcUtil.isICSOrLater()) // NOP check return;/*ww w. java 2 s.c o m*/ Media media = getCurrentMedia(); if (mRemoteControlClient != null && media != null) { MetadataEditor editor = mRemoteControlClient.editMetadata(true); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre()); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle()); editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength()); // Copy the cover bitmap because the RemonteControlClient can // recycle its artwork bitmap. Bitmap cover = getCover(); editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, ((cover != null) ? cover.copy(cover.getConfig(), false) : null)); editor.apply(); } }
From source file:com.android.contacts.common.ContactPhotoManager.java
/** * If necessary, decodes bytes stored in the holder to Bitmap. As long as the * bitmap is held either by {@link #mBitmapCache} or by a soft reference in * the holder, it will not be necessary to decode the bitmap. *///from w w w. j a v a 2s. c om private static void inflateBitmap(BitmapHolder holder, int requestedExtent) { final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent); byte[] bytes = holder.bytes; if (bytes == null || bytes.length == 0) { return; } if (sampleSize == holder.decodedSampleSize) { // Check the soft reference. If will be retained if the bitmap is also // in the LRU cache, so we don't need to check the LRU cache explicitly. if (holder.bitmapRef != null) { holder.bitmap = holder.bitmapRef.get(); if (holder.bitmap != null) { return; } } } try { Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize); // TODO: As a temporary workaround while framework support is being added to // clip non-square bitmaps into a perfect circle, manually crop the bitmap into // into a square if it will be displayed as a thumbnail so that it can be cropped // into a circle. final int height = bitmap.getHeight(); final int width = bitmap.getWidth(); // The smaller dimension of a scaled bitmap can range from anywhere from 0 to just // below twice the length of a thumbnail image due to the way we calculate the optimal // sample size. if (height != width && Math.min(height, width) <= mThumbnailSize * 2) { final int dimension = Math.min(height, width); bitmap = ThumbnailUtils.extractThumbnail(bitmap, dimension, dimension); } // make bitmap mutable and draw size onto it if (DEBUG_SIZES) { Bitmap original = bitmap; bitmap = bitmap.copy(bitmap.getConfig(), true); original.recycle(); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setTextSize(16); paint.setColor(Color.BLUE); paint.setStyle(Style.FILL); canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint); paint.setColor(Color.WHITE); paint.setAntiAlias(true); canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint); } holder.decodedSampleSize = sampleSize; holder.bitmap = bitmap; holder.bitmapRef = new SoftReference<Bitmap>(bitmap); if (DEBUG) { Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x" + bitmap.getHeight() + ", " + btk(bitmap.getByteCount())); } } catch (OutOfMemoryError e) { // Do nothing - the photo will appear to be missing } }