activity 之间直接传递图片时
Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");

去掉seekBarBackground
创建一个blank drawable 然后satBar.setProgressDrawable(invisibleBackground);
也许这样也可以setBackgroundDrawable(null)


1、Drawable → Bitmap
public static Bitmap drawableToBitmap(Drawable drawable) {

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);
//canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}

public static Bitmap drawableToBitmap(Drawable drawable) {

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);
//canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}

2、从资源中获取Bitmap



Java代码
Resources res=getResources();

Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic);

Resources res=getResources();

Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic);

3、Bitmap → byte[]



Java代码
private byte[] Bitmap2Bytes(Bitmap bm){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}

private byte[] Bitmap2Bytes(Bitmap bm){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
4、 byte[] → Bitmap

Java代码
private Bitmap Bytes2Bimap(byte[] b){
if(b.length!=0){
return BitmapFactory.decodeByteArray(b, 0, b.length);
}
else {
return null;
}
}

更多相关文章

  1. 收集到的Android开源代码
  2. Android(安卓)JNI技术, NDK开发
  3. Android中常用的bitmap处理方法 (bitmap工具类)
  4. Android(安卓)-- 跨应用启动Service
  5. Android上的Ubuntu Debian Armel
  6. Android(安卓)Bitmap用法总结
  7. Android(安卓)webview上传图片(相册/相机)
  8. Android(安卓)主动 try-catch 主线程的 Exception
  9. Android(安卓)活动的最佳实践

随机推荐

  1. 物理网卡故障,怎么办?
  2. 2020.2.22 每日小结
  3. 类成员重载-全局成员-命名空间声明访问分
  4. zabbix安装
  5. Netdata 新一代实时监控系统(4)
  6. 接口联动
  7. 接口的基本属性
  8. 面试被问离职原因该怎么回答?
  9. 服务器Web性能测试主要包含四个方面详解
  10. 2021软件测试发展的15种趋势,别怪我没告诉