當前位置: 首頁>>代碼示例>>Java>>正文


Java BitmapDrawable類代碼示例

本文整理匯總了Java中android.graphics.drawable.BitmapDrawable的典型用法代碼示例。如果您正苦於以下問題:Java BitmapDrawable類的具體用法?Java BitmapDrawable怎麽用?Java BitmapDrawable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BitmapDrawable類屬於android.graphics.drawable包,在下文中一共展示了BitmapDrawable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createBitmapFromView

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
/**
 * 從一個view創建Bitmap。
 * 注意點:繪製之前要清掉 View 的焦點,因為焦點可能會改變一個 View 的 UI 狀態。
 * 來源:https://github.com/tyrantgit/ExplosionField
 *
 * @param view  傳入一個 View,會獲取這個 View 的內容創建 Bitmap。
 * @param scale 縮放比例,對創建的 Bitmap 進行縮放,數值支持從 0 到 1。
 */
public static Bitmap createBitmapFromView(View view, float scale) {
    if (view instanceof ImageView) {
        Drawable drawable = ((ImageView) view).getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }
    }
    view.clearFocus();
    Bitmap bitmap = createBitmapSafely((int) (view.getWidth() * scale),
            (int) (view.getHeight() * scale), Bitmap.Config.ARGB_8888, 1);
    if (bitmap != null) {
        synchronized (sCanvas) {
            Canvas canvas = sCanvas;
            canvas.setBitmap(bitmap);
            canvas.save();
            canvas.drawColor(Color.WHITE); // 防止 View 上麵有些區域空白導致最終 Bitmap 上有些區域變黑
            canvas.scale(scale, scale);
            view.draw(canvas);
            canvas.restore();
            canvas.setBitmap(null);
        }
    }
    return bitmap;
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:33,代碼來源:QMUIDrawableHelper.java

示例2: createBitmapFromView

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
/**
 * 從視圖創建位圖
 * @param view
 * @return
 */
public static Bitmap createBitmapFromView(View view) {
	if (view instanceof ImageView) {
		Drawable drawable = ((ImageView) view).getDrawable();
		if (drawable != null && drawable instanceof BitmapDrawable) {
			return ((BitmapDrawable) drawable).getBitmap();
		}
	}
	view.clearFocus();
	Bitmap bitmap = createBitmapSafely(view.getWidth(),
			view.getHeight(), Bitmap.Config.ARGB_8888, 1);
	if (bitmap != null) {
		synchronized (sCanvas) {
			Canvas canvas = sCanvas;
			canvas.setBitmap(bitmap);
			view.draw(canvas);
			canvas.setBitmap(null);
		}
	}
	return bitmap;
}
 
開發者ID:A-Miracle,項目名稱:QiangHongBao,代碼行數:26,代碼來源:BitmapUtils.java

示例3: createProductImageDrawable

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
private Drawable createProductImageDrawable(Product product) {
    final ShapeDrawable background = new ShapeDrawable();
    background.setShape(new OvalShape());
    background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));

    final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
        BitmapFactory.decodeResource(getResources(), product.image));

    final LayerDrawable layerDrawable = new LayerDrawable
        (new Drawable[]{background, bitmapDrawable});

    final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
    layerDrawable.setLayerInset(1, padding, padding, padding, padding);

    return layerDrawable;
}
 
開發者ID:saulmm,項目名稱:From-design-to-Android-part1,代碼行數:17,代碼來源:OrderDialogFragment.java

示例4: onPostExecute

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
protected void onPostExecute(Drawable d) {
    if (d != null) {
        if (imgView != null)
            imgView.setImageDrawable(d);
        BitmapDrawable bd = (BitmapDrawable) d;
        Bitmap bmp = bd.getBitmap();
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, s);
        if (mFIsThumbnail)
            m_imgThumb = s.toByteArray();
        else
            m_imgData = s.toByteArray();

        if (m_icc != null)
            m_icc.imgCompleted(MFBImageInfo.this);
    }
}
 
開發者ID:ericberman,項目名稱:MyFlightbookAndroid,代碼行數:18,代碼來源:MFBImageInfo.java

示例5: badgeIconForUser

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
/**
 * Badges the provided icon with the user badge if required.
 */
public static Bitmap badgeIconForUser(Bitmap icon,  UserHandleCompat user, Context context) {
    if (Utilities.ATLEAST_LOLLIPOP && user != null
            && !UserHandleCompat.myUserHandle().equals(user)) {
        BitmapDrawable drawable = new FixedSizeBitmapDrawable(icon);
        Drawable badged = context.getPackageManager().getUserBadgedIcon(
                drawable, user.getUser());
        if (badged instanceof BitmapDrawable) {
            return ((BitmapDrawable) badged).getBitmap();
        } else {
            return createIconBitmap(badged, context);
        }
    } else {
        return icon;
    }
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:19,代碼來源:Utilities.java

示例6: onDraw

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    Drawable drawable = getDrawable();
    if (drawable instanceof BitmapDrawable) {
        RectF rectF = new RectF(drawable.getBounds());
        int restoreCount = canvas.saveLayer(rectF, null, Canvas.ALL_SAVE_FLAG);
        getImageMatrix().mapRect(rectF);

        Paint paint = ((BitmapDrawable) drawable).getPaint();
        paint.setAntiAlias(true);
        paint.setColor(0xff000000);

        canvas.drawARGB(0, 0, 0, 0);
        canvas.drawRoundRect(rectF, RADIUS, RADIUS, paint);

        Xfermode restoreMode = paint.getXfermode();
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        super.onDraw(canvas);

        // Restore paint and canvas
        paint.setXfermode(restoreMode);
        canvas.restoreToCount(restoreCount);
    } else {
        super.onDraw(canvas);
    }
}
 
開發者ID:Kaufland,項目名稱:andcouchbaseentity,代碼行數:27,代碼來源:RoundImageView.java

示例7: startImageFrame

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
public void startImageFrame(final ImageFrameHandler imageFrameHandler) {
  if (this.imageFrameHandler == null) {
    this.imageFrameHandler = imageFrameHandler;
  }else{
    this.imageFrameHandler.stop();
    this.imageFrameHandler = imageFrameHandler;
  }
  imageFrameHandler.setOnImageLoaderListener(new ImageFrameHandler.OnImageLoadListener() {
    @Override
    public void onImageLoad(BitmapDrawable drawable) {
      ViewCompat.setBackground(ImageFrameCustomView.this, drawable);
    }

    @Override
    public void onPlayFinish() {

    }
  });
  post(new Runnable() {
    @Override
    public void run() {
      imageFrameHandler.start();
    }
  });

}
 
開發者ID:Mr-wangyong,項目名稱:ImageFrame,代碼行數:27,代碼來源:ImageFrameCustomView.java

示例8: onCreate

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    new FetchItemsTask().execute();

    Handler responseHandler = new Handler();
    mThumbnailDownloader = new ThumbnailDownloader<>(responseHandler);
    mThumbnailDownloader.setThumbnailDownloadListener(
        new ThumbnailDownloader.ThumbnailDownloadListener<PhotoHolder>() {
            @Override
            public void onThumbnailDownloaded(PhotoHolder photoHolder, Bitmap bitmap) {
                Drawable drawable = new BitmapDrawable(getResources(), bitmap);
                photoHolder.bindDrawable(drawable);
            }
        }
    );
    mThumbnailDownloader.start();
    mThumbnailDownloader.getLooper();
    Log.i(TAG, "Background thread started");
}
 
開發者ID:rsippl,項目名稱:AndroidProgramming3e,代碼行數:22,代碼來源:PhotoGalleryFragment.java

示例9: renderDrawable

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
private Bitmap renderDrawable(final Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    final Rect bounds = drawable.getBounds();
    final Bitmap bitmap = Bitmap.createBitmap(
            bounds.width(),
            bounds.height(),
            Bitmap.Config.ARGB_8888
    );

    final Canvas canvas = new Canvas(bitmap);
    canvas.translate(-bounds.left, -bounds.top);
    drawable.draw(canvas);

    return bitmap;
}
 
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:19,代碼來源:ColorizedCardView.java

示例10: drawable2Bitmap

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
private 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;
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:21,代碼來源:SpanUtils.java

示例11: onViewClicked

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
@OnClick({R.id.start, R.id.red_line, R.id.gray_line})
public void onViewClicked(View view) {
    switch (view.getId()) {
        case R.id.start:
            Bitmap bp = pint1.createSnapshoot();
            Drawable dw = new BitmapDrawable(getResources(),bp);
            im.setImageDrawable(dw);

            break;
        case R.id.red_line:
            break;
        case R.id.gray_line:

            break;
    }
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:17,代碼來源:SurroundTestFragment.java

示例12: drawable2Bitmap

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
/**
 * drawable轉bitmap
 *
 * @param drawable drawable對象
 * @return bitmap
 */
public static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof NinePatchDrawable) {
        Bitmap 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, drawable.getIntrinsicWidth(), drawable
                .getIntrinsicHeight());
        drawable.draw(canvas);
        return bitmap;
    } else {
        return null;
    }
}
 
開發者ID:imliujun,項目名稱:LJFramework,代碼行數:26,代碼來源:ImageUtils.java

示例13: drawableToBitmap

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
/**
 * Creates a Bitmap object from a Drawable object.
 */
private static Bitmap drawableToBitmap(Drawable dr) {
    // Attempt to retrieve any existing Bitmap, if possible
    if (dr instanceof BitmapDrawable) {
        BitmapDrawable bDr = (BitmapDrawable)dr;
        if (bDr.getBitmap() != null) {
            return bDr.getBitmap();
        }
    }

    // Create a valid blank Bitmap
    final Bitmap bitmap;
    if (dr.getIntrinsicWidth() <= 0 || dr.getIntrinsicHeight() <= 0) {
        // Single color bitmap will be create of 1x1 pixel
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    } else {
        bitmap = Bitmap.createBitmap(dr.getIntrinsicWidth(),
                dr.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    }

    // Use our Canvas to draw the Drawable onto the Bitmap
    Canvas canvas = new Canvas(bitmap);
    dr.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    dr.draw(canvas);
    return bitmap;
}
 
開發者ID:tylersuehr7,項目名稱:chips-input-layout,代碼行數:29,代碼來源:LetterTileProvider.java

示例14: PicPopupWindow

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
private PicPopupWindow(Context context) {
	mContext = context;
	mInflater = (LayoutInflater) mContext
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	mPopupContent = (ViewGroup) mInflater.inflate(
			R.layout.popup_window_list, null);
	mPopupItemContent = (ViewGroup) mPopupContent
			.findViewById(R.id.popup_window_item_content);
	title = (TextView) mPopupContent
			.findViewById(R.id.popup_window_title_text);
	mPopupWindow = new PopupWindow(mPopupContent,
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	mPopupWindow.setFocusable(true);
	mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
	mPopupWindow.setOnDismissListener(new OnDismissListener() {
		@Override
		public void onDismiss() {
			// TODO Auto-generated method stub
			resetItemByTag(setTag);
			if (mAnimationListener != null) {
				mAnimationListener.doAnimation(false);
			}
		}
	});
	mPopupWindow.setAnimationStyle(R.style.popup_window_animation);
}
 
開發者ID:YuntaoWei,項目名稱:PictureShow,代碼行數:27,代碼來源:PicPopupWindow.java

示例15: blurAdvanced

import android.graphics.drawable.BitmapDrawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void blurAdvanced(Context context, Bitmap bkg, View view) {
    if (bkg != null) {
        Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(overlay);
        Paint paint = new Paint();
        paint.setFlags(2);
        canvas.drawBitmap(bkg, 0.0f, 0.0f, paint);
        overlay = FastBlur.doBlur(overlay, (int) 12.0f, true);
        if (LetvUtils.getSDKVersion() >= 16) {
            view.setBackground(new BitmapDrawable(context.getResources(), overlay));
        } else {
            view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:17,代碼來源:BlurUtils.java


注:本文中的android.graphics.drawable.BitmapDrawable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。