android.graphics.drawable.BitmapDrawable Java Examples

The following examples show how to use android.graphics.drawable.BitmapDrawable. 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 check out the related API usage on the sidebar.
Example #1
Source File: DisplayQRCode.java    From Rumble with 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 File: ConvertUtils.java    From AndroidWallet with 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 File: MusicPlayerView.java    From IdealMedia with 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 File: ImageCache.java    From RoMote with 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 #5
Source File: ImageLoader.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #6
Source File: ContextUtils.java    From memetastic with 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 #7
Source File: Marker.java    From osmdroid with 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 #8
Source File: LocalRepoManager.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #9
Source File: NewTabPageView.java    From delion with 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 #10
Source File: NotificationListenerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** 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 #11
Source File: PXDrawableUtil.java    From pixate-freestyle-android with 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 #12
Source File: IosButton.java    From HumanBody with 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 #13
Source File: SettingPopup.java    From KakaoBot with 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 #14
Source File: AvatarService.java    From Conversations with 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 #15
Source File: ImageCache.java    From malevich with 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 #16
Source File: ImageUtility.java    From CameraV with 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 #17
Source File: RoundedImageView.java    From android-apps with 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 #18
Source File: BootstrapDrawableFactory.java    From Android-Bootstrap with 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 #19
Source File: ArtLoader.java    From android-vlc-remote with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Drawable loadInBackground() {
    Resources res = getContext().getResources();
    if(mMediaServer == null) {
        return res.getDrawable(R.drawable.albumart_mp_unknown);
    }
    try {
        return new BitmapDrawable(res, mMediaServer.art().read());
    } catch (IOException e) {
        return res.getDrawable(R.drawable.albumart_mp_unknown);
    }
}
 
Example #20
Source File: MapTileProviderBase.java    From osmdroid with 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 #21
Source File: SharedElementCallback.java    From letv with 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 #22
Source File: CacheUtils.java    From CrawlerForReader with 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 #23
Source File: ImageReceiver.java    From Telegram with 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 #24
Source File: CircleImageView.java    From Place-Search-Service with MIT License 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 #25
Source File: MyUtils.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
public static void releaseBackgroundResource(Context context, View v){
	BitmapDrawable bd=(BitmapDrawable)v.getBackground();
	v.setBackgroundResource(0);
	if (bd != null){
		bd.setCallback(null);
		if (bd.getBitmap() != null){
			bd.getBitmap().recycle();
		}
	}
}
 
Example #26
Source File: ImageProvider.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
private void setLoadedBitmap(ImageView imageView, Bitmap bitmap, String tag) {
    if (!tag.equals(imageView.getTag()))
        return;

    final TransitionDrawable transition = new TransitionDrawable(new Drawable[]{
            new ColorDrawable(android.R.color.transparent),
            new BitmapDrawable(imageView.getResources(), bitmap)
    });

    imageView.setImageDrawable(transition);
    final int duration = imageView.getResources().getInteger(R.integer.image_fade_in_duration);
    transition.startTransition(duration);
}
 
Example #27
Source File: UserSettingsFragment.java    From android-skeleton-project with MIT License 5 votes vote down vote up
private void processImageResponse(String id, ImageResponse response) {
    if (response != null) {
        Bitmap bitmap = response.getBitmap();
        if (bitmap != null) {
            BitmapDrawable drawable = new BitmapDrawable(UserSettingsFragment.this.getResources(), bitmap);
            drawable.setBounds(0, 0,
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_width),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_height));
            userProfilePic = drawable;
            userProfilePicID = id;
            connectedStateLabel.setCompoundDrawables(null, drawable, null, null);
            connectedStateLabel.setTag(response.getRequest().getImageUri());
        }
    }
}
 
Example #28
Source File: ModifyUserDataActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
private void setPicToView(Intent picdata) {
    Bundle extras = picdata.getExtras();
    if (extras != null) {
        Bitmap photo = extras.getParcelable("data");
        Drawable drawable = new BitmapDrawable(getResources(), photo);
        iv_head.setImageDrawable(drawable);
        head_b = Bitmap2Bytes(photo);
        modifyHead();
    }

}
 
Example #29
Source File: MainActivity.java    From google-io-2014-compat with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void startActivityLollipop(View view, Intent intent) {
    intent.setClass(this, DetailActivityL.class);
    ImageView hero = (ImageView) ((View) view.getParent()).findViewById(R.id.photo);
    ((ViewGroup) hero.getParent()).setTransitionGroup(false);

    sPhotoCache.put(intent.getIntExtra("photo", -1),
            ((BitmapDrawable) hero.getDrawable()).getBitmap());

    ActivityOptions options =
            ActivityOptions.makeSceneTransitionAnimation(this, hero, "photo_hero");
    startActivity(intent, options.toBundle());
}
 
Example #30
Source File: ImageFloderPop.java    From ImagePicker with Apache License 2.0 5 votes vote down vote up
/**
 * 从Activity底部弹出来
 */
public void showAtBottom(Activity activity, View parent, ImageFolderBean curFloder, onFloderItemClickListener listener)
{
    this.mActReference = new WeakReference<>(activity);
    this.mListener = listener;

    View contentView = LayoutInflater.from(activity).inflate(R.layout.layout_image_floder_pop, null);
    int height = activity.getResources().getDimensionPixelSize(R.dimen.imagepicker_floder_pop_height);
    mPopupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, height, true);
    mPopupWindow.setBackgroundDrawable(new BitmapDrawable());// 响应返回键必须的语句。
    mPopupWindow.setFocusable(true);//设置pop可获取焦点
    mPopupWindow.setAnimationStyle(R.style.FloderPopAnimStyle);//设置显示、消失动画
    mPopupWindow.setOutsideTouchable(true);//设置点击外部可关闭pop
    mPopupWindow.setOnDismissListener(this);

    mListView = (ListView) contentView.findViewById(R.id.lv_image_floder_pop);
    final int position = ImageDataModel.getInstance().getAllFolderList().indexOf(curFloder);
    mAdapter = new ImageFloderAdapter(activity, position);
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(this);

    mPopupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
    toggleWindowAlpha();

    // 增加绘制监听
    ViewTreeObserver vto = mListView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
        @Override
        public void onGlobalLayout()
        {
            // 移除监听
            mListView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            mListView.setSelection(position);
        }
    });
}