<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

    主站蜘蛛池模板: 亚洲精品无码激情AV| 四虎影永久在线高清免费| 亚洲AV无码精品色午夜在线观看| AV激情亚洲男人的天堂国语| 在线精品免费视频无码的| 亚洲国产高清视频在线观看| 美女视频黄a视频全免费| ass亚洲**毛茸茸pics| 国产成人精品久久免费动漫| 亚洲成电影在线观看青青| 黄页网站在线看免费| 亚洲国产日韩精品| 日本免费无遮挡吸乳视频电影| 美女羞羞免费视频网站| 久久久久亚洲精品中文字幕| 97无码人妻福利免费公开在线视频 | 7m凹凸精品分类大全免费| 亚洲天堂男人天堂| 无码人妻久久一区二区三区免费丨| 亚洲色精品VR一区区三区| 亚洲成人国产精品| 国产午夜成人免费看片无遮挡| 精品日韩亚洲AV无码一区二区三区| 4455永久在线观免费看| 亚洲一本到无码av中文字幕| 亚洲高清无码专区视频| 久久99精品国产免费观看| 国产成人精品亚洲日本在线| 国产v片免费播放| 久久免费视频观看| 亚洲 日韩经典 中文字幕| 亚洲日本在线观看视频| 日本免费大黄在线观看| 亚洲精品无码久久久久秋霞| 亚洲日韩中文在线精品第一| 亚洲网站免费观看| 免费很黄无遮挡的视频毛片| 久久精品国产亚洲AV网站| 午夜时刻免费入口| 97无码人妻福利免费公开在线视频 | 亚洲黄色网址在线观看|