如何将捕获的图片保存为SQLite作为blob和检索回PhoneGap? [英] How to Save Captured Picture into SQLite as blob and Retrieve back in Phonegap?

查看:131
本文介绍了如何将捕获的图片保存为SQLite作为blob和检索回PhoneGap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建的Phonegap项目,使用相机捕获图片 http://mobile.tutsplus.com/tutorials/phonegap/phonegap-from-scratch-camera-exporting/.Now 我想将图像保存为blob到sqlite数据库。此外,一旦保存检索和显示图像。请建议。

I have a created Phonegap Project that captures a Picture using Camera following the tutorial http://mobile.tutsplus.com/tutorials/phonegap/phonegap-from-scratch-camera-exporting/.Now I want to save the image as blob into a sqlite database. Also once saved retrieve and display the image. Please suggest.

推荐答案

请按照以下步骤

1 。现在将Base 64转换为Blob对象

Please follow below step
1. Get Your picture as base 64 using phone gap Camera API
2. Now convert Base 64 to Blob object

function convertDataURIToBlob(dataURI, mimetype) {
    var BASE64_MARKER= ';base64,';
    var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
    var base64 = dataURI.substring(base64Index);  
    var raw = window.atob(base64);
    var rawLength = raw.length;
    var uInt8Array = new Uint8Array(rawLength);
    for (var i = 0; i < rawLength; ++i) {
        uInt8Array[i] = raw.charCodeAt(i);   
    }
    var bb = new BlobBuilder();
    bb.append(uInt8Array.buffer);
    return bb.getBlob(mimetype); 
}


而不是传递mimetype,
数据网址,并与getBlob()一起使用。



使用此插件


3。现在可以使用phonegap Storage API将图片保存到Sqlite列数据类型为字符串。

4。使用Phone gap存储API从Sqlite中获取Blob对象

5。使用Java脚本将此对象表示为HTMl标记。
将样本blob对象转换为HTML 5


Instead of passing in a mimetype though, you should extract it from the data url and use that with getBlob().
OR
use this plugin
3. Now you can save your image using phonegap Storage API to Sqlite your desired column data type is string.
4. Fetch your blob object from Sqlite using Phone gap Storage API
5. Now represent this object to HTMl tag using Java script.Here sample blob object to HTML 5

<!DOCTYPE html>    
<html>    
<head>    
    <meta charset="utf-8" />    
    <title>Blob</title>    
    <script type="text/javascript">    
        (function () {    
            window.URL = window.URL || window.webkitURL;    
            function contentLoaded() {    
                var blob = new Blob(['alert("hello")'], { type: 'text/javascript' });    
                var script = document.createElement('script');    
                script.setAttribute('src', window.URL.createObjectURL(blob));    
                document.body.appendChild(script);    
            }    
            window.addEventListener('DOMContentLoaded', contentLoaded, false);    
        } ());    
    </script>    
</head>    
<body>    
    <div id="container">    
    </div>    
</body>    
</html>

这篇关于如何将捕获的图片保存为SQLite作为blob和检索回PhoneGap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆