Java Code Examples for android.graphics.drawable.BitmapDrawable

The following examples show how to use android.graphics.drawable.BitmapDrawable. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Rumble   Source File: DisplayQRCode.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_qrcode);

    Intent intent = getIntent();
    bitmap = (Bitmap) intent.getParcelableExtra("EXTRA_QRCODE");
    String name   = (String) intent.getStringExtra("EXTRA_GROUP_NAME");
    String buffer = (String) intent.getStringExtra("EXTRA_BUFFER");

    setTitle(name);
    getSupportActionBar().hide();

    ImageView qrView = (ImageView)findViewById(R.id.qrcode);
    TextView  bufView = (TextView)findViewById(R.id.buffer);

    Drawable drawable = new BitmapDrawable(getResources(), bitmap);
    qrView.setImageDrawable(drawable);
    bufView.setText(buffer);
}
 
Example 2
Source Project: AndroidWallet   Source File: ConvertUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * drawable转bitmap
 *
 * @param drawable drawable对象
 * @return bitmap
 */
public static Bitmap drawable2Bitmap(final Drawable drawable) {
    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,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
Example 3
Source Project: IdealMedia   Source File: MusicPlayerView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * We need to convert drawable (which we get from attributes) to bitmap
 * to prepare if for BitmapShader
 *
 * @param drawable
 * @return
 */
private Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    int width = drawable.getIntrinsicWidth();
    width = width > 0 ? width : 1;
    int height = drawable.getIntrinsicHeight();
    height = height > 0 ? height : 1;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}
 
Example 4
Source Project: delion   Source File: NewTabPageView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onLargeIconAvailable(Bitmap icon, int fallbackColor) {
    if (icon == null) {
        mIconGenerator.setBackgroundColor(fallbackColor);
        icon = mIconGenerator.generateIconForUrl(mItem.getUrl());
        mItemView.setIcon(new BitmapDrawable(getResources(), icon));
        mItem.setTileType(fallbackColor == ICON_BACKGROUND_COLOR
                ? MostVisitedTileType.ICON_DEFAULT : MostVisitedTileType.ICON_COLOR);
    } else {
        RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(
                getResources(), icon);
        int cornerRadius = Math.round(ICON_CORNER_RADIUS_DP
                * getResources().getDisplayMetrics().density * icon.getWidth()
                / mDesiredIconSize);
        roundedIcon.setCornerRadius(cornerRadius);
        roundedIcon.setAntiAlias(true);
        roundedIcon.setFilterBitmap(true);
        mItemView.setIcon(roundedIcon);
        mItem.setTileType(MostVisitedTileType.ICON_REAL);
    }
    mSnapshotMostVisitedChanged = true;
    if (mIsInitialLoad) loadTaskCompleted();
}
 
Example 5
/** Convert new-style Icons to legacy representations for pre-M clients. */
private void createLegacyIconExtras(Notification n) {
    Icon smallIcon = n.getSmallIcon();
    Icon largeIcon = n.getLargeIcon();
    if (smallIcon != null && smallIcon.getType() == Icon.TYPE_RESOURCE) {
        n.extras.putInt(Notification.EXTRA_SMALL_ICON, smallIcon.getResId());
        n.icon = smallIcon.getResId();
    }
    if (largeIcon != null) {
        Drawable d = largeIcon.loadDrawable(getContext());
        if (d != null && d instanceof BitmapDrawable) {
            final Bitmap largeIconBits = ((BitmapDrawable) d).getBitmap();
            n.extras.putParcelable(Notification.EXTRA_LARGE_ICON, largeIconBits);
            n.largeIcon = largeIconBits;
        }
    }
}
 
Example 6
Source Project: HumanBody   Source File: IosButton.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 传入改变亮度前的bitmap,返回改变亮度后的bitmap
 * @author leibing
 * @createTime 2016/12/30
 * @lastModify 2016/12/30
 * @param srcBitmap
 * @return
 */
   @SuppressWarnings("deprecation")
public Drawable changeBrightnessBitmap(Bitmap srcBitmap){  
        Bitmap bmp = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(),    
               Config.ARGB_8888);    
       int brightness = 60 - 127;    
       ColorMatrix cMatrix = new ColorMatrix();
	// 改变亮度
       cMatrix.set(new float[] { 1, 0, 0, 0, brightness, 0, 1,    
               0, 0, brightness,
               0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 });    
       Paint paint = new Paint();    
       paint.setColorFilter(new ColorMatrixColorFilter(cMatrix));    
       Canvas canvas = new Canvas(bmp);    
       // 在Canvas上绘制一个Bitmap  
       canvas.drawBitmap(srcBitmap, 0, 0, paint);    
      return new BitmapDrawable(bmp);  
   }
 
Example 7
Source Project: KakaoBot   Source File: SettingPopup.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void init() {
    LinearLayout frame = new LinearLayout(context);
    CardView card = new CardView(context);

    card.setUseCompatPadding(true);
    card.setContentPadding(MainActivity.dp(8), MainActivity.dp(8), MainActivity.dp(8), MainActivity.dp(8));
    card.setCardElevation(12.f);

    card.addView(layout);
    frame.addView(card);

    this.setContentView(frame);
    this.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    this.setFocusable(true);
    this.setBackgroundDrawable(new BitmapDrawable());
    this.setOutsideTouchable(true);
}
 
Example 8
Source Project: Conversations   Source File: AvatarService.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static Bitmap getRoundLauncherIcon(Resources resources) {

		final Drawable drawable = ResourcesCompat.getDrawable(resources, R.mipmap.new_launcher_round,null);
		if (drawable == null) {
			return null;
		}

		if (drawable instanceof BitmapDrawable) {
			return ((BitmapDrawable)drawable).getBitmap();
		}

		Bitmap 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;
	}
 
Example 9
Source Project: android-apps   Source File: RoundedImageView.java    License: MIT License 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas){
	Drawable drawable = getDrawable();
	
	if( drawable == null ){
		return;
	}
	
	if( getWidth() == 0 || getHeight() == 0 ){
		return;
	}
	
	Bitmap b = ( (BitmapDrawable) drawable ).getBitmap();
	Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
	
	int w = getWidth(), h = getHeight();
	
	Bitmap roundBitmap = getRoundedCroppedBitmap(bitmap, w);
	canvas.drawBitmap(roundBitmap, 0, 0, null);
}
 
Example 10
Source Project: letv   Source File: SharedElementCallback.java    License: Apache License 2.0 6 votes vote down vote up
private static Bitmap createDrawableBitmap(Drawable drawable) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    if (width <= 0 || height <= 0) {
        return null;
    }
    float scale = Math.min(1.0f, ((float) MAX_IMAGE_SIZE) / ((float) (width * height)));
    if ((drawable instanceof BitmapDrawable) && scale == 1.0f) {
        return ((BitmapDrawable) drawable).getBitmap();
    }
    int bitmapWidth = (int) (((float) width) * scale);
    int bitmapHeight = (int) (((float) height) * scale);
    Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Rect existingBounds = drawable.getBounds();
    int left = existingBounds.left;
    int top = existingBounds.top;
    int right = existingBounds.right;
    int bottom = existingBounds.bottom;
    drawable.setBounds(0, 0, bitmapWidth, bitmapHeight);
    drawable.draw(canvas);
    drawable.setBounds(left, top, right, bottom);
    return bitmap;
}
 
Example 11
Source Project: CrawlerForReader   Source File: CacheUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static Bitmap drawable2Bitmap(final Drawable drawable) {
    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,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
Example 12
Source Project: osmdroid   Source File: MapTileProviderBase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void computeTile(final long pMapTileIndex, final int pX, final int pY) {
	// get the correct fraction of the tile from cache and scale up

	final long oldTile = MapTileIndex.getTileIndex(mOldTileZoomLevel,
			MapTileIndex.getX(pMapTileIndex) >> mDiff, MapTileIndex.getY(pMapTileIndex) >> mDiff);
	final Drawable oldDrawable = mTileCache.getMapTile(oldTile);

	if (oldDrawable instanceof BitmapDrawable) {
		final Bitmap bitmap = MapTileApproximater.approximateTileFromLowerZoom(
				(BitmapDrawable)oldDrawable, pMapTileIndex, mDiff);
		if (bitmap != null) {
			mNewTiles.put(pMapTileIndex, bitmap);
		}
	}
}
 
Example 13
Source Project: Android-Bootstrap   Source File: BootstrapDrawableFactory.java    License: MIT License 6 votes vote down vote up
private static Drawable createCloseCrossIcon(Context context, int width, int height, int color, int inset) {
    Bitmap canvasBitmap = Bitmap.createBitmap(width + inset * 2, height + inset * 2, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(canvasBitmap);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setStrokeWidth(3);
    paint.setColor(color);
    paint.setAntiAlias(true);
    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(inset, inset);
    path.lineTo(width + inset, height + inset);
    path.moveTo(width + inset, inset);
    path.lineTo(inset, height + inset);
    path.close();
    canvas.drawPath(path, paint);
    return new BitmapDrawable(context.getResources(), canvasBitmap);
}
 
Example 14
Source Project: malevich   Source File: ImageCache.java    License: MIT License 6 votes vote down vote up
/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (Malevich.Utils.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (Malevich.Utils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}
 
Example 15
Source Project: CameraV   Source File: ImageUtility.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static Bitmap drawableToBitmap(Drawable d) {
	if(d instanceof BitmapDrawable) {
		return ((BitmapDrawable) d).getBitmap();
	}
	
	int w = d.getIntrinsicWidth();
	w = w > 0 ? w : 1;
	
	int h = d.getIntrinsicHeight();
	h = h > 0 ? h : 1;
	
	Bitmap b = Bitmap.createBitmap(w, h, Config.ARGB_8888);
	Canvas c = new Canvas(b);
	d.setBounds(0, 0, c.getWidth(), c.getHeight());
	d.draw(c);
	
	return b;
}
 
Example 16
Source Project: pixate-freestyle-android   Source File: PXDrawableUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets a {@link Bitmap} background. In case the call is set to check for a
 * layer-drawable and there is an existing {@link LayerDrawable} on the
 * given View, set/replace the layer with the
 * {@code android.R.id.background} id.
 * 
 * @param view
 * @param bitmap
 * @param checkForLayer Indicate if this method should check for a
 *            {@link LayerDrawable} when applying a background.
 */
public static void setBackground(View view, Bitmap bitmap, boolean checkForLayer) {
    if (view instanceof ImageView) {
        ((ImageView) view).setImageBitmap(bitmap);
        return;
    }
    BitmapDrawable newDrawable = new BitmapDrawable(PixateFreestyle.getAppContext()
            .getResources(), bitmap);
    Drawable background = view.getBackground();
    if (background instanceof ColorDrawable) {
        // keep the background color so it would show when the bitmap is
        // transparent
        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background,
                newDrawable });
        layerDrawable.setId(1, android.R.id.background);
        setBackgroundDrawable(view, layerDrawable);
    } else {
        setBackgroundDrawable(view, newDrawable, checkForLayer);
    }
}
 
Example 17
Source Project: memetastic   Source File: ContextUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get a {@link Bitmap} out of a {@link Drawable}
 */
public Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;
    if (drawable instanceof VectorDrawableCompat
            || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable)
            || ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && drawable instanceof AdaptiveIconDrawable))) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        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);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
 
Example 18
/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView The ImageView to set the bitmap to.
 * @param bitmap    The new bitmap to set.
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {

    if (mFadeInBitmap) {
        // Transition drawable to fade from loading bitmap to final bitmap
        final TransitionDrawable td =
                new TransitionDrawable(new Drawable[]{
                        new ColorDrawable(android.R.color.transparent),
                        new BitmapDrawable(mResources, bitmap)
                });
        imageView.setBackgroundDrawable(imageView.getDrawable());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}
 
Example 19
Source Project: RoMote   Source File: ImageCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get from memory cache.
 *
 * @param data Unique identifier for which item to get
 * @return The bitmap drawable if found in cache, null otherwise
 */
public BitmapDrawable getBitmapFromMemCache(String data) {
    //BEGIN_INCLUDE(get_bitmap_from_mem_cache)
    BitmapDrawable memValue = null;

    if (mMemoryCache != null) {
        memValue = mMemoryCache.get(data);
    }

    if (BuildConfig.DEBUG && memValue != null) {
        Log.d(TAG, "Memory cache hit");
    }

    return memValue;
    //END_INCLUDE(get_bitmap_from_mem_cache)
}
 
Example 20
/**
 * Extracts the icon from an APK and writes it to the repo as a PNG
 */
private void copyIconToRepo(Drawable drawable, String packageName, int versionCode) {
    Bitmap bitmap;
    if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    }
    File png = getIconFile(packageName, versionCode);
    OutputStream out;
    try {
        out = new BufferedOutputStream(new FileOutputStream(png));
        bitmap.compress(CompressFormat.PNG, 100, out);
        out.close();
    } catch (Exception e) {
        Log.e(TAG, "Error copying icon to repo", e);
    }
}
 
Example 21
Source Project: osmdroid   Source File: Marker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @since 6.0.3
 */
public void setTextIcon(final String pText) {
	final Paint background = new Paint();
	background.setColor(mTextLabelBackgroundColor);
	final Paint p = new Paint();
	p.setTextSize(mTextLabelFontSize);
	p.setColor(mTextLabelForegroundColor);
	p.setAntiAlias(true);
	p.setTypeface(Typeface.DEFAULT_BOLD);
	p.setTextAlign(Paint.Align.LEFT);
	final int width = (int) (p.measureText(pText) + 0.5f);
	final float baseline = (int) (-p.ascent() + 0.5f);
	final int height = (int) (baseline + p.descent() + 0.5f);
	final Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
	final Canvas c = new Canvas(image);
	c.drawPaint(background);
	c.drawText(pText, 0, baseline, p);
	mIcon = new BitmapDrawable(mResources, image);
	setAnchor(ANCHOR_CENTER, ANCHOR_CENTER);
}
 
Example 22
Source Project: Telegram   Source File: ImageReceiver.java    License: GNU General Public License v2.0 6 votes vote down vote up
public BitmapHolder getBitmapSafe() {
    Bitmap bitmap = null;
    String key = null;
    AnimatedFileDrawable animation = getAnimation();
    RLottieDrawable lottieDrawable = getLottieAnimation();
    if (lottieDrawable != null && lottieDrawable.hasBitmap()) {
        bitmap = lottieDrawable.getAnimatedBitmap();
    } else if (animation != null && animation.hasBitmap()) {
        bitmap = animation.getAnimatedBitmap();
    } else if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        bitmap = ((BitmapDrawable) currentMediaDrawable).getBitmap();
        key = currentMediaKey;
    } else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        bitmap = ((BitmapDrawable) currentImageDrawable).getBitmap();
        key = currentImageKey;
    } else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        bitmap = ((BitmapDrawable) currentThumbDrawable).getBitmap();
        key = currentThumbKey;
    } else if (staticThumbDrawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) staticThumbDrawable).getBitmap();
    }
    if (bitmap != null) {
        return new BitmapHolder(bitmap, key);
    }
    return null;
}
 
Example 23
@TargetApi(21)
private byte[] getTestPicture() {
    byte[] bytes = new byte[1024];
    int resId = Connect.getInstance().getResources().getIdentifier("test","drawable",Connect.getInstance().getPackageName());
    Drawable image = Connect.getInstance().getDrawable(resId);
    Bitmap bitmap = ((BitmapDrawable)image).getBitmap();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
    bytes = stream.toByteArray();
    return bytes;
}
 
Example 24
Source Project: Android-Bootstrap   Source File: BootstrapDrawableFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Creates arrow icon that depends on ExpandDirection
 *
 * @param context context
 * @param width  width of icon in pixels
 * @param height height of icon in pixels
 * @param color arrow color
 * @param expandDirection arrow direction
 * @return icon drawable
 */
private static Drawable createArrowIcon(Context context, int width, int height, int color, ExpandDirection expandDirection) {
    Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(canvasBitmap);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setStrokeWidth(1);
    paint.setColor(color);
    paint.setAntiAlias(true);
    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);
    switch (expandDirection) {
        case UP:
            path.moveTo(0, (height / 3) * 2);
            path.lineTo(width, (height / 3) * 2);
            path.lineTo(width / 2, height / 3);
            path.lineTo(0, (height / 3) * 2);
            break;
        case DOWN:
            path.moveTo(0, height / 3);
            path.lineTo(width, height / 3);
            path.lineTo(width / 2, (height / 3) * 2);
            path.lineTo(0, height / 3);
            break;
    }
    path.close();
    canvas.drawPath(path, paint);
    return new BitmapDrawable(context.getResources(), canvasBitmap);
}
 
Example 25
Source Project: AdvancedMaterialDrawer   Source File: MaterialHeadItem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Drawable doInBackground(Integer... params) {
    Point photoSize = Utils.getUserPhotoSize(resources);
    Bitmap photo = Utils.resizeBitmapFromResource(resources, params[0], photoSize.x, photoSize.y);
    BitmapDrawable photoD = new BitmapDrawable(resources, photo);
    photo.recycle();
    return photoD;
}
 
Example 26
Source Project: MemorySpinner   Source File: MemoryCache.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static Drawable bitmap2Drawable(Bitmap bm) {
	if (bm == null) {
		return null;
	}
	BitmapDrawable bd=new BitmapDrawable(bm);
	bd.setTargetDensity(bm.getDensity());
	return new BitmapDrawable(bm);
}
 
Example 27
public void setData(String paintPath, ArrayList<VideoEditedInfo.MediaEntity> entities, boolean isVideo, boolean startAfterSet) {
    if (paintPath != null) {
        paintBitmap = BitmapFactory.decodeFile(paintPath);
        setBackground(backgroundDrawable = new BitmapDrawable(paintBitmap));
    } else {
        paintBitmap = null;
        setBackground(backgroundDrawable = null);
    }
    setEntities(entities, isVideo, startAfterSet);
}
 
Example 28
public BitmapHolder getThumbBitmapSafe() {
    Bitmap bitmap = null;
    String key = null;
    if (currentThumb instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) currentThumb).getBitmap();
        key = currentThumbKey;
    } else if (staticThumb instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) staticThumb).getBitmap();
    }
    if (bitmap != null) {
        return new BitmapHolder(bitmap, key);
    }
    return null;
}
 
Example 29
Source Project: ToDoList   Source File: CircleImageView.java    License: Apache License 2.0 5 votes vote down vote up
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 30
Source Project: 365browser   Source File: BookmarkItemRow.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onLargeIconAvailable(
        Bitmap icon, int fallbackColor, boolean isFallbackColorDefault) {
    if (icon == null) {
        mIconGenerator.setBackgroundColor(fallbackColor);
        icon = mIconGenerator.generateIconForUrl(mUrl);
        mIconImageView.setImageDrawable(new BitmapDrawable(getResources(), icon));
    } else {
        RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(
                getResources(),
                Bitmap.createScaledBitmap(icon, mDisplayedIconSize, mDisplayedIconSize, false));
        roundedIcon.setCornerRadius(mCornerRadius);
        mIconImageView.setImageDrawable(roundedIcon);
    }
}