`
- 浏览:
59145 次
- 性别:
- 来自:
北京
-
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;
}
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
VB 图片转换为Byte()和从Byte()中读取图片的捷径
把图片(jpg、png)转换成byte[]比特流流的小工具。
这个工程是简单将String和byte[]互相转换的Demo,有需要的可以下载
android byte字节数组转换十六进制字符串一个demo。里面有几种转换测试代码。我的博客地址:http://blog.csdn.net/qq_16064871。
把图片(jpg、png)转换成Base64的小工具。
Cstring 与BYTE类型之间转换,实现字节与字符串的转换,将字符串转化为字节类型。0进制与16进制间转换
将图片转成byte及将byte转成图片..........................................
1、把一张图片(png bmp jpeg bmp gif)转换为byte数组存放到数据库。 2、把从数据库读取的byte数组转换为Image对象,赋值给相应的控件显示。 3、从图片byte数组得到对应图片的格式,生成一张图片保存到磁盘上。 ...
1.字符串(String)与Byte[] 的互相转换. 2.Hex(String形式)与Byte[] 的互相转换.
byte数组、十进制、十六进制间的两两转换
Base64与byte[]相互转换 将base64转换为byte[] 转byet[]换为base64 并在base64中去掉换行
C# 图片转成byte存入,数据库读取byte转成图片的类
将Image数据转换为byte数组,便于网络图片传输
unity AudioClip各种转换 Byte[] float[] , 方便上传服务器,下载播放
详细的介绍了android_Drawable、Bitmap、byte[]之间的转换 在android开发中非常实用
Android Drawable、Bitmap、byte、灰度 转换
将byte数组转化为图片,可以是灰度图片或者RGB图片,原理都是一样 的
Java String与Byte类型转换;用到网络编程.
做Java课程设计有用到的例子,是个看了就能上手的例子。
图片转换成字节流先要转换的IMage对象,转换之后返回字节流。字节流转换成图片,要转换的字节流,转换得到的Image对象,根据图片路径返回图片的字节流,感兴趣的朋友看下下面的代码。 C#将图片和字节流相互转换代码...