Android获得图片资源的三种方式
生活随笔
收集整理的這篇文章主要介紹了
Android获得图片资源的三种方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
一、??????? 使用BitmapFactory解析圖片
// --> 使用BitmapFactory解析圖片 public void myUseBitmapFactory(Canvas canvas){ // 定義畫筆Paint paint = new Paint(); // 獲取資源流Resources rec = getResources();InputStream in = rec.openRawResource(R.drawable.haha); // 設置圖片Bitmap bitmap =BitmapFactory.decodeStream(in); // 繪制圖片canvas.drawBitmap(bitmap, 0,20, paint); }二、??????? 使用BitmapDrawable解析圖片
// --> 使用BitmapDrawable解析圖片public void myUseBitmapDrawable(Canvas canvas){// 定義畫筆Paint paint = new Paint();// 獲得資源Resources rec = getResources();// BitmapDrawableBitmapDrawable bitmapDrawable = (BitmapDrawable) rec.getDrawable(R.drawable.haha);// 得到BitmapBitmap bitmap = bitmapDrawable.getBitmap();// 在畫板上繪制圖片canvas.drawBitmap(bitmap, 20,120,paint);}三、??????? 使用InputStream和BitmapDrawable繪制
// --> 使用InputStream和BitmapDrawable解析圖片public void myUseInputStreamandBitmapDrawable(Canvas canvas){// 定義畫筆Paint paint = new Paint();// 獲得資源Resources rec = getResources();// InputStream得到資源流InputStream in = rec.openRawResource(R.drawable.haha);// BitmapDrawable 解析數據流BitmapDrawable bitmapDrawable = new BitmapDrawable(in);// 得到圖片Bitmap bitmap = bitmapDrawable.getBitmap();// 繪制圖片canvas.drawBitmap(bitmap, 100, 100,paint);}轉載于:https://www.cnblogs.com/riaol/archive/2012/02/08/2343210.html
總結
以上是生活随笔為你收集整理的Android获得图片资源的三种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 页面回传与js调用服务器端事件(转)
- 下一篇: Android 内容提供器---内容提供