Foxtable(狐表)用户栏目专家坐堂 → 调用相册


  共有2030人关注过本帖树形打印复制链接

主题:调用相册

帅哥哟,离线,有人找我吗?
刘林
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1936 积分:14844 威望:0 精华:0 注册:2016/4/28 9:58:00
调用相册  发帖心情 Post By:2018/9/16 14:34:00 [只看该作者]

Dim e As RequestEventArgs = args(0)
Dim path As String = "foxtableAppTest"
Dim wb As New weui
wb.InsertHTML("<!DOCTYPE html>")
wb.InsertHTML("<html>")
wb.InsertHTML("<head>")
wb.InsertHTML("<meta charset='utf-8'>")
wb.InsertHTML("<meta name='viewport' c />")
wb.InsertHTML("<title></title>")
wb.InsertHTML("<script src='../mui/js/mui.min.js'></script>")
wb.InsertHTML("<link href='../mui/css/mui.css' rel='stylesheet'/>")
wb.InsertHTML("<script Type='text/javascript' charset='utf-8'>mui.init();</script>")
wb.InsertHTML("</head>")
wb.InsertHTML("<body>")
wb.InsertHTML("<header class='mui-bar mui-bar-nav mui-bar-nav-bg'>")
wb.InsertHTML("<a  id='icon-menu' class='mui-action-back mui-icon mui-icon-left-nav mui-pull-left'></a>")
'wb.InsertHTML ("<a class='mui-action-back mui-icon mui-icon-home mui-pull-right mui-a-color'></a>")
wb.InsertHTML("<h1 class='mui-title'>我的照片</h1>")
wb.InsertHTML("</header>")
wb.InsertHTML("<div class='mui-content'>")
wb.InsertHTML("<br>")
wb.InsertHTML("<br>")
wb.AddForm("","form1","xpcj.htm")
If e.PostValues.Count = 0 Then
    wb.InsertHTML("form1","<div style='height: 150px;'><span style='position:absolute;margin-top:60px;margin-left:20px;'>我的照片:</span><img alt='你还没有照片' src='./xp/" & e.Cookies("username") & ".jpg' style='height: 150px;width:120px;margin-left:120px;max-height:100%'></div><br>")
    If ReadSex(e.Cookies("username"))= "女"
        wb.InsertHTML("form1","<div style='height: 170px'><span style='position:absolute;margin-top:70px;margin-left:20px;'>样板照片:</span><div id='imgs'><img src='./xp/yb.jpg' style='height:150px;width:120px;margin-top:20px;margin-left:120px;max-height:100%;'></div></div><br/>")
    End If
    If ReadSex(e.Cookies("username"))= "男"
        wb.InsertHTML("form1","<div style='height:150px'><span style='position:absolute;margin-top:70px;margin-left:20px;'>样板照片:</span><div id='imgs' style='widht:120px;height:150px;'><img src='./xp/yb1.jpg' style='height:150px;width:120px;margin-left:120px;max-height:100%;'></div></div><br/>")
    End If
    With wb.AddPageFooter("form1","pf1","")
        With wb.AddButtonGroup("form1","btg1",False)
            Dim bt1= .Add("btn1", "拍照", "button")
            bt1.Attribute = "onclick=getImageByCamera('imgs') style='border:1px solid black;border-radius:40px;padding:0px;'"
            bt1.kind=1
            'Dim bt2= .Add("btn2", "相册", "button")
           ' bt2.Attribute = "style='border:1px solid black;border-radius:40px;padding:0px;"
           ' bt2.kind=1
            Dim bt3=.Add("btn3", "上传")
            bt3.kind=1
            bt3.attribute="style='border:1px solid black;border-radius:40px;padding:0px;'onclick=javascript:mui.toast('正在上传,请等待');"
        End With
    End With
 wb.InsertHTML("<input Type='file' accept='image/*' style='border:1px solid black;border-radius:40px;padding:0px;' value='相册'> ")
Else
    For Each key As String In e.PostValues.Keys
        If key.Contains("imgs_") Then
            Dim bs As Byte() = Convert.FromBase64String(e.PostValues(key).split(",")(1))
            Dim stream As System.IO.Stream = New System.IO.MemoryStream(bs)
            Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(stream)
            bmp.Save("c:\web\xp\" & e.Cookies("username") & ".jpg", ImageFormat.Jpeg)
            Dim slt As String ="c:\web\xp\" & e.Cookies("username") & ".jpg"
            Dim img1 As image = getImage(slt)
            Dim bmp1 As bitmap
            If img1.width > 800 Then
                If 800 * (img1.height / img1.width) > 600 Then
                    bmp1 = new bitmap(img1, 800*(600/(800*(img1.height/img1.width))), 600)
                Else
                    bmp1 = new bitmap(img1, 600, 600 * (img1.height / img1.width))
                End If
            End If
            bmp1.save(slt, ImageFormat.Jpeg)
            bmp1.Dispose
        End If
    Next
    With wb.AddMsgPage("","msgpage","上传成功", "") '生成成功提示页
        Dim bt1=.AddButton("btn1","确定","xpcj.htm")
        bt1.kind=1
        bt1.Attribute = "style='border:1px solid black;border-radius:20px;padding:0px;width:50%'"
        
    End With
End If
wb.AppendHTML("<script type='text/javascript' src='/" & path & "/js/common.js'></script>", True)
wb.AppendHTML("<script type='text/javascript' src='/" & path & "/js/camera.js'></script>")
e.WriteString(wb.Build)


老师请问两个问题,
1.现在这个页面做了调用摄像头照像,并压缩上传是可以了,现在想加一个打开相册将选定图片显示在imgs中,这个红色部分如何改,或者加一个按钮调用相册并将选定图片显示在imgs中
2.为了将上传成功的图片在本页中显出来, 用了  Dim bt1=.AddButton("btn1","确定","xpcj.htm"),但如果用顶部返回键要按两次才退出本页,有什么办法可以按顶部返回一次退出


 回到顶部
帅哥哟,离线,有人找我吗?
刘林
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1936 积分:14844 威望:0 精华:0 注册:2016/4/28 9:58:00
  发帖心情 Post By:2018/9/16 14:38:00 [只看该作者]


图片点击可在新窗口打开查看此主题相关图片如下:screenshot_2018-09-16-14-35-14-65.png
图片点击可在新窗口打开查看

现在页面如上

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/16 16:36:00 [只看该作者]

看懂 hbuilder 里面的例子吧,里面有调用相册的实例的

 

帮助文档看懂一下 http://www.html5plus.org/doc/zh_cn/gallery.html

 


 回到顶部
帅哥哟,离线,有人找我吗?
刘林
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1936 积分:14844 威望:0 精华:0 注册:2016/4/28 9:58:00
  发帖心情 Post By:2018/9/17 8:48:00 [只看该作者]




 wb.InsertHTML("form1","<div style='height: 170px'><span style='position:absolute;margin-top:70px;margin-left:20px;'>样板照片:</span><div id='imgs'><img src='./xp/yb.jpg' 
style='height:150px;width:120px;margin-top:20px;margin-left:120px;max-height:100%;'></div></div><br/>")
  Dim bt2= .Add("btn2", "相册", "button")
            bt2.Attribute = "onclick=galleryImg() style='border:1px solid black;border-radius:40px;padding:0px;‘"
            bt2.kind=1


现在打包后是可以调出相册了, 但请问如何将选定的单个图片文件放到id='imgs'控件中显示出来呢?谢谢
[此贴子已经被作者于2018/9/17 8:48:37编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/17 9:07:00 [只看该作者]

比较麻烦,看懂例子

 

https://blog.csdn.net/qq_27626333/article/details/51896616

 

主要是选择后,得到路径读取图片,压缩图片得到图片数据,然后显示出来


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/17 9:20:00 [只看该作者]

以下是引用有点甜在2018/9/17 9:07:00的发言:

比较麻烦,看懂例子

 

https://blog.csdn.net/qq_27626333/article/details/51896616

 

主要是选择后,得到路径读取图片,压缩图片得到图片数据,然后显示出来

 

也就是类似你【拍照】的代码,拍照之后不是保存了一个文件,然后读取文件展示出来么?

 

选择图片后,也是类似这样做的。


 回到顶部
帅哥哟,离线,有人找我吗?
刘林
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1936 积分:14844 威望:0 精华:0 注册:2016/4/28 9:58:00
  发帖心情 Post By:2018/9/17 10:30:00 [只看该作者]

功力不够,弄不好,请你帮写一个具体操作的嘛,谢谢

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/17 10:32:00 [只看该作者]

以下是引用刘林在2018/9/17 10:30:00的发言:
功力不够,弄不好,请你帮写一个具体操作的嘛,谢谢

 

1、5楼就是例子啊,有实例啊。

 

2、如果不懂,去看懂你原来的【拍照】的代码怎么写。


 回到顶部
帅哥哟,离线,有人找我吗?
刘林
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1936 积分:14844 威望:0 精华:0 注册:2016/4/28 9:58:00
  发帖心情 Post By:2018/9/17 17:53:00 [只看该作者]

   Dim bt2= .Add("btn2", "相册", "button")
            bt2.Attribute = "onclick=galleryImg('imgs') style='border:1px solid black;border-radius:40px;padding:0px;'"
            bt2.kind=1


js


var count = 1;
function galleryImg(id) {
plus.camera.getCamera().captureImage(function(p) {
var imgs = document.galleryImg(id);
plus.io.resolveLocalFileSystemURL(p, function(entry) {
entry.file(function(file) {

var url = entry.toLocalURL();
var name = "_doc/upload/" + entry.name;
plus.zip.compressImage({
src: url, //src: (String 类型 )压缩转换原始图片的路径    
dst: name, //压缩转换目标图片的路径    
quality: 100, //quality: (Number 类型 )压缩图片的质量.取值范围为1-100    
overwrite: true //overwrite: (Boolean 类型 )覆盖生成新文件    
},
function(zip) {
//页面显示图片  
showPics(zip.target, name, id);
},
function(error) {
plus.nativeUI.toast("压缩图片失败,请稍候再试");
});

});
});
});
}

function showPics(p, name, id) {
var imgs = document.getElementById(id);
plus.io.resolveLocalFileSystemURL(p, function(entry) {
entry.file(function(file) {
var fileReader = new plus.io.FileReader();
fileReader.readAsDataURL(file);
fileReader.onloadend = function(e) {
var picUrl = e.target.result.toString();

imgs.innerHTML = "<img src='" + picUrl + "' style='height:150px;width:120px;margin-top:20px;margin-left:120px;margin-Bottom:20px;max-height:100%;'/><input type='hidden' name='" + id + "_" + count + "' value='" + picUrl + "'/>"
}
});
});
}


改不对,请老师帮看一下该怎么改

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/17 18:00:00 [只看该作者]

拍照的代码改成选择图片的代码就行啊

 

    plus.gallery.pick( function(path){
     console.log(path);
    }, function ( e ) {
     console.log( "取消选择图片" );
    }, {filter:"image"} );

 

比如

 

plus.camera.getCamera().captureImage(function(p) {

 

改成

 

plus.gallery.pick( function(p){


 回到顶部
总数 15 1 2 下一页