码迷,mamicode.com
首页 > Web开发 > 详细

关于JS将图片回显问题,将byte[]转化为流,信息填入input框内

时间:2020-04-07 22:36:56      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:mic   width   str   group   com   照片   control   关于   buffer   

 1   <script>
 2 
 3         var For_photo = []
 4         var normal_data = new Object();
 5         var Userinfo = JSON.parse(sessionStorage.getItem(Userinformation));
 6         for (var prop in Userinfo) {
 7             //$("[name=‘" + prop + "‘]").val(ForeignTeachers[prop]);//遍历了整个数据
 8             if (prop == "PHOTO") {
 9                 //eval("For_photo." + prop + "=‘" + ForeignTeachers[prop] + "‘");
10                 //For_photo.push(ForeignTeachers[prop])
11                 var str = arrayBufferToBase64(Userinfo[prop]);
12                 $("#" + prop).attr("src", data:image/png;base64, + str);
13             }
14             else {
15                 //normal_data.push(ForeignTeachers[prop]);
16                 eval("normal_data." + prop + "=‘" + Userinfo[prop] + "");
17                 $("[name=‘" + prop + "‘]").val(Userinfo[prop]);//遍历了整个数据
18             }
19         }
20 
21         //将byte[]转化为流
22         function arrayBufferToBase64(buffer) {
23             var binary = ‘‘;
24             var bytes = new Uint8Array(buffer);
25             var len = bytes.byteLength;
26             for (var i = 0; i < len; i++) {
27                 binary += String.fromCharCode(bytes[i]);
28             }
29             return window.btoa(binary);
30             return binary;
31         }
32         </script>

技术图片

 

 关于C#后端传过来的byte[],然后js转化流,然后显示图片.

 

   <div class="col-md-12" id="uploadForm">
                        <div class="form-group  col-md-6 " style="text-align:center">
                            <label class="col-sm-2 control-label">资料照片</label>
                            <div class="col-sm-6 fileinput fileinput-new" data-provides="fileinput" id="exampleInputUpload">
                                <div class="fileinput-new thumbnail" style="width: 200px;height: auto;max-height:150px;">
                                    <img id=‘PHOTO‘ style="width: 100%;height: auto;max-height: 140px;" src="~/Content/css/extra-images/noimage.png"  />
                                </div>
                                <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                                <div>
                                    <span class="btn btn-primary btn-file">
                                        <span class="fileinput-new">上传</span>
                                        <span class="fileinput-exists">更改</span>
                                        <input type="file" name="PHOTO" id="user_photo" accept="image/gif,image/jpeg,image/x-png" />
                                    </span>
                                    <a href="javascript:;" class="btn btn-warning fileinput-exists" data-dismiss="fileinput">Remove</a>
                                </div>
                            </div>
                        </div>

                    </div>

 

关于JS将图片回显问题,将byte[]转化为流,信息填入input框内

标签:mic   width   str   group   com   照片   control   关于   buffer   

原文地址:https://www.cnblogs.com/yuanmo/p/12656267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!