当前位置: 首页>>代码示例>>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;未经允许,请勿转载。