<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 33, 文章 - 0, 評論 - 12, 引用 - 0
    數據加載中……

    android 保存圖片到數據庫

    方法一:
    Java代碼 復制代碼
    1. public void saveIcon(Bitmap icon) {   
    2.         if (icon == null) {   
    3.             return;   
    4.         }   
    5.   
    6.         // 最終圖標要保存到瀏覽器的內部數據庫中,系統程序均保存為SQLite格式,Browser也不例外,因為圖片是二進制的所以使用字節數組存儲數據庫的   
    7.         // BLOB類型   
    8.         final ByteArrayOutputStream os = new ByteArrayOutputStream();   
    9.         // 將Bitmap壓縮成PNG編碼,質量為100%存儲           
    10.         icon.compress(Bitmap.CompressFormat.PNG, 100, os);    
    11.         // 構造SQLite的Content對象,這里也可以使用raw   
    12.         ContentValues values = new ContentValues();    
    13.         // 寫入數據庫的Browser.BookmarkColumns.TOUCH_ICON字段   
    14.         values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray());    
    15.            
    16.         DBUtil.update(....);//調用更新或者插入到數據庫的方法   
    17.     } 


    方法二:如果數據表入口時一個content:URI

     

    Java代碼 復制代碼
    1. import android.provider.MediaStore.Images.Media;   
    2. import android.content.ContentValues;   
    3. import java.io.OutputStream;   
    4.   
    5. // Save the name and description of an image in a ContentValues map.     
    6. ContentValues values = new ContentValues(3);   
    7. values.put(Media.DISPLAY_NAME, "road_trip_1");   
    8. values.put(Media.DESCRIPTION, "Day 1, trip to Los Angeles");   
    9. values.put(Media.MIME_TYPE, "image/jpeg");   
    10.   
    11. // Add a new record without the bitmap, but with the values just set.   
    12. // insert() returns the URI of the new record.   
    13. Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);   
    14.   
    15. // Now get a handle to the file for that record, and save the data into it.   
    16. // Here, sourceBitmap is a Bitmap object representing the file to save to the database.   
    17. try {   
    18.     OutputStream outStream = getContentResolver().openOutputStream(uri);   
    19.     sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream);   
    20.     outStream.close();   
    21. catch (Exception e) {   
    22.     Log.e(TAG, "exception while writing image", e);   


    posted on 2011-11-17 14:09 建華 閱讀(1664) 評論(0)  編輯  收藏 所屬分類: Android

    主站蜘蛛池模板: 毛片免费视频观看| 国产2021精品视频免费播放| 亚洲高清中文字幕| 国色精品va在线观看免费视频| 精品国产日韩亚洲一区| 国产成人无码精品久久久久免费| 亚洲国产成人五月综合网 | 久久av免费天堂小草播放| 亚洲无码黄色网址| 国产猛男猛女超爽免费视频| 亚洲AV成人一区二区三区AV| 蜜桃AV无码免费看永久| 中文无码亚洲精品字幕| 国产乱子伦精品免费无码专区| 一区免费在线观看| 久久久久亚洲AV成人无码网站| 亚洲精品在线免费观看视频| 欧洲 亚洲 国产图片综合| 国产视频精品免费| 99久久成人国产精品免费| 亚洲电影免费观看| 色播在线永久免费视频| 一区二区三区在线免费| 亚洲卡一卡2卡三卡4卡无卡三| 免费精品国产日韩热久久| 国产亚洲美女精品久久久久| 亚洲精品成人无码中文毛片不卡| **毛片免费观看久久精品| 久久久久亚洲精品无码网址色欲| 亚洲综合亚洲综合网成人| 无码免费一区二区三区免费播放| 亚洲综合久久一本伊伊区| 亚洲日韩在线第一页| 麻花传媒剧在线mv免费观看| 国产精品自拍亚洲| 97亚洲熟妇自偷自拍另类图片 | 免费看一级做a爰片久久| 中文字幕无码免费久久| 亚洲综合精品第一页| 国产精品亚洲片在线观看不卡 | 亚洲国产一成久久精品国产成人综合|