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; }
相关推荐
public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } Bitmap bitmap = Bitmap.createBitmap(drawable...
public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....
public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....
public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } int width = drawable.getIntrinsicWidth(); ...
public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....
public static Bitmap drawableToBitmap(Drawable drawable) { int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != PixelFormat....
public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....
上面的`drawableToBitmap(Drawable drawable)`方法就实现了这个功能。它首先创建一个Bitmap对象,根据Drawable的宽度、高度和透明度来确定Bitmap的配置,然后创建一个Canvas,将Drawable绘制到Canvas上,最后返回这...
private Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != Pixel...
public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat....
在这个示例中,我们使用了两个不同的drawable资源,并通过`drawableToBitmap()`方法将其转换为Bitmap。这个方法接收一个Drawable对象,然后创建一个与之匹配大小的Bitmap,并在Canvas上绘制Drawable,最后返回Bitmap...
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_image); ``` 2. **从文件加载**: 使用`decodeFile()`方法加载本地文件系统的图片。 ```java File file = new File("/path/to/...
可以使用Drawable.toBitmap()方法完成转换。 在实际开发中,我们可能需要封装一个自定义视图来处理这个功能。自定义视图需要继承View或者ImageView,重写onDraw()方法,在这里执行我们的裁剪逻辑。用户可以通过触摸...
public static Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap.Config config = (drawable.getOpacity() != ...
在使用Canvas绘制图片时,为了避免“Immutable bitmap passed to Canvas constructor”错误,我们需要确保使用的Bitmap是可以修改的,因此在解码资源时,我们使用了.copy()方法创建了一个可变的Bitmap副本。...
本文实例讲述了android图片类型...public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawa
转换 – drawable To bitmap 缩放 – Zoom 圆角 – Round Corner 倒影 – Reflected bitmapPrcess code: package com.learn.games; import android.graphics.Bitmap; import android.graphics.Canvas; import...