Android中Bitmap、Drawable、byte[]转换(hdp)
来源:互联网 发布:作图软件哪个好 编辑:程序博客网 时间:2024/05/17 21:58
1.Drawable—>Bitmap
Resources res=getResources();Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.sample_0);
2.Bitmap---->Drawable
Drawable drawable =new BitmapDrawable(bmp);
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的宽高 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap;}
2、从资源中获取Bitmap
Resources res=getResources();Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic);
3、Bitmap → byte[]
private byte[] Bitmap2Bytes(Bitmap bm){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
4、 byte[] → Bitmap
private Bitmap Bytes2Bimap(byte[] b){ if(b.length!=0){ return BitmapFactory.decodeByteArray(b, 0, b.length); } else { return null; } }hdp.li.fans.bitmapcache;
构造函数:protected ImageWorker(Context context) {mResources = context.getResources();} /xlh_addpublic void loadImage(Object data, ImageView imageView) {if (data == null) {Log.v("xulongheng*moredetails*bitmap", "moredetails*");Bitmap bitmap = BitmapFactory.decodeResource( mResources, R.drawable.moredetails);imageView.setImageBitmap(createSaledBitmap(bitmap));return;}if(data.toString().indexOf("://")<0){imageView.setImageResource(R.drawable.moren);return;}Bitmap bitmap = null;if (mImageCache != null) {bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data));} if (bitmap != null && !bitmap.isRecycled()) {// Bitmap found in memory cacheimageView.setImageBitmap(createSaledBitmap(bitmap));if(mImageLoadCompletedListener!=null){mImageLoadCompletedListener.setCustomImageView(imageView, bitmap);}} else if (cancelPotentialWork(data, imageView)) {final BitmapWorkerTask task = new BitmapWorkerTask(imageView);/*if (mLoadingBitmap != null && !mLoadingBitmap.isRecycled()) {*/final AsyncDrawable asyncDrawable;if (mImageLoadCompletedListener != null) {asyncDrawable = new AsyncDrawable(mResources,mImageLoadCompletedListener.setCustomBitmap(createSaledBitmap(mLoadingBitmap)),task);} else {asyncDrawable = new AsyncDrawable(mResources,createSaledBitmap(mLoadingBitmap), task);//xlh_?}imageView.setImageDrawable(asyncDrawable);//}// NOTE: This uses a custom version of AsyncTask that has been// pulled from the// framework and slightly modified. Refer to the docs at the top of// the class// for more info on what was changed.task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data);}}
- Android中Bitmap、Drawable、byte[]转换(hdp)
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换 (
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Drawable、Bitmap、byte
- android 中byte[] bitmap drawable inputstream的相互转换
- Android中Bitmap, ID,Drawable, Byte之间的转换
- android Bitmap、Drawable、byte[]相互转换
- Android Drawable、Bitmap、byte[]之间的转换
- Android Drawable、Bitmap、byte[]之间的转换
- Android Drawable、Bitmap、byte[]之间的转换
- android中点中overlay弹出带尾巴的气泡的实现
- c++代码的陪伴下----菜鸟的转变
- 数据库编码改为utf-8
- 两种方式实现仿微信标题栏弹窗效果
- rpm spec
- Android中Bitmap、Drawable、byte[]转换(hdp)
- QC080000有害物质认证产生的背景
- ExtJS4单击Backspace页面回退
- list 排序
- OS X Mountain Lion 系统配置 Apache+Mysql+PHP 详细教程
- 转战csdn
- QML - 可视元素 Image
- Socket与拔掉网线
- c# 经典排序算法