`
zengxx1989
  • 浏览: 300319 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
社区版块
存档分类
最新评论

android drawableToBitmap Drawable 转换成 Bitmap

 
阅读更多
	private static Bitmap drawableToBitmap(Drawable drawable) {
		if (drawable == null) {
			return null;
		}
		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());
		Log.i("Utilities",
				"drawableToBitmap drawable.getIntrinsicWidth()=" + drawable.getIntrinsicWidth()
						+ ",drawable.getIntrinsicHeight()="
						+ drawable.getIntrinsicHeight());
		drawable.draw(canvas);
		return bitmap;
	}

 

分享到:
评论

相关推荐

    Android Drawable Bitmap 相互转换

    public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } Bitmap bitmap = Bitmap.createBitmap(drawable...

    Android Drawable、Bitmap、byte、灰度 转换

    public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....

    Android Drawable、Bitmap、byte、灰度 之间的转换

    public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....

    Drawable Bitmap之间的转化

    public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } int width = drawable.getIntrinsicWidth(); ...

    android_Drawable、Bitmap、byte[]之间的转换.doc

    public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....

    android bitMap

    public static Bitmap drawableToBitmap(Drawable drawable) { int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != PixelFormat....

    android Bitmap用法总结

    public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....

    androidbitmap的用法.pdf

    上面的`drawableToBitmap(Drawable drawable)`方法就实现了这个功能。它首先创建一个Bitmap对象,根据Drawable的宽度、高度和透明度来确定Bitmap的配置,然后创建一个Canvas,将Drawable绘制到Canvas上,最后返回这...

    Android 将本地资源图片转换成Drawable,进行设置大小操作

    private Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != Pixel...

    android bitmap

    public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....

    Android界面 NotificationManager使用Bitmap做图标

    在这个示例中,我们使用了两个不同的drawable资源,并通过`drawableToBitmap()`方法将其转换为Bitmap。这个方法接收一个Drawable对象,然后创建一个与之匹配大小的Bitmap,并在Canvas上绘制Drawable,最后返回Bitmap...

    Android Bitmap使用demo

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_image); ``` 2. **从文件加载**: 使用`decodeFile()`方法加载本地文件系统的图片。 ```java File file = new File("/path/to/...

    android 图片任意截取

    可以使用Drawable.toBitmap()方法完成转换。 在实际开发中,我们可能需要封装一个自定义视图来处理这个功能。自定义视图需要继承View或者ImageView,重写onDraw()方法,在这里执行我们的裁剪逻辑。用户可以通过触摸...

    android ui

    public static Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap.Config config = (drawable.getOpacity() != ...

    Android实现图片叠加效果的两种方法

    在使用Canvas绘制图片时,为了避免“Immutable bitmap passed to Canvas constructor”错误,我们需要确保使用的Bitmap是可以修改的,因此在解码资源时,我们使用了.copy()方法创建了一个可变的Bitmap副本。...

    android图片类型之间相互转换实现代码

    本文实例讲述了android图片类型...public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawa

    Android编程中图片特效处理方法小结

    转换 – drawable To bitmap 缩放 – Zoom 圆角 – Round Corner 倒影 – Reflected bitmapPrcess code: package com.learn.games; import android.graphics.Bitmap; import android.graphics.Canvas; import...

Global site tag (gtag.js) - Google Analytics