首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从数据库中获取图像

从数据库中获取图像
EN

Stack Overflow用户
提问于 2015-02-11 17:08:23
回答 1查看 240关注 0票数 0
代码语言:javascript
运行
复制
function PgMain_rptArticles_OnRowRender(e){
    var records = Data.execute('select * from Articles');
    Data.Dataset1.seek(e.rowIndex);

       Pages.PgMain.rptArticles.Image1.image = records.rows[e.rowIndex][3];
       Pages. PgMain.rptArticles.Label1.text = records.rows[e.rowIndex][1];
       Pages. PgMain.rptArticles.Label2.text = records.rows[e.rowIndex][2]       
}

如何从数据库中获取图像?

EN

回答 1

Stack Overflow用户

发布于 2015-02-12 15:02:52

将大型二进制文件直接保存到数据库是非常罕见的。更常见的方法是将图像保存到文件中,并保存到数据库的路径。

很少有讨论:

How to store image in SQLite database

Android Save images to SQLite or SDCard or memory

saving image into SQLITE?

我假设您希望保存对数据库的引用,而我的答案基于此。

请看下面的示例:File.htm

代码语言:javascript
运行
复制
SMF.Multimedia.startCamera({
    cameraType : 1, //rear camera
    resolution : 2, //large resolution
    autoFocus : true,
    onStart : function () {}, //do nothing
    onCapture : function (e) {
        var photoFile = new SMF.IO.File(e.photoUri); //the full URI is given
        var destination = SMF.IO.applicationDataDirectory + //predefined path already containing separator at the end
            "data" + SMF.IO.pathSeperator + "tbl1" +
            SMF.IO.pathSeperator + photoFile.name; //name gives file name with extension
        var targetFile =  new SMF.IO.File(destination);
        if(!targetFile.exists) {
            if(photoFile.move(destination)) { //if moved successfully
                //photoFile nativePath has been updated
                Data.execute("Insert into tbl1 (image) values(?)",
                    photoFile.nativePath); //records reference to database
            }
        }
    },
    onCancel : function () {}, //do nothing
    onFailure : function () {}
    //do nothing
});

您将将“目的地”变量(引用上面的示例)保存到数据库中,然后抓取部分将如下所示:

代码语言:javascript
运行
复制
Pages.PgMain.rptArticles.Image1.image = SMF.Image(records.rows[e.rowIndex][3]);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28460235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档