在html / js windows universal app 8.1中通过后台传输上传之前调整图像大小 [英] resize image before upload via background transfer in html/js windows universal app 8.1

查看:88
本文介绍了在html / js windows universal app 8.1中通过后台传输上传之前调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想调整从手机图库中挑选的图片,然后通过后台传输上传它到目前为止我有: -

   filePicker    pickSingleFileAsync  ()。 然后   function      file      {  
uploadSingleFileAsync
uri file );
})。 完成 null displayException );

function uploadSingleFileAsync uri file {
if (! file < span class ="pun"style ="margin:0px; padding:0px; border:0px; vertical-align:baseline; color:#000000; background:transparent">) {
displayError
"错误:未选择文件。" );
return ;
}
return 文件 getBasicPropertiesAsync ()。 然后 function properties {
if properties size > maxUploadFileSize {
displayError
"所选文件超过最大上传文件大小(" + maxUploadFileSize / 1024 * 1024 )) +
" MB)。" );
return ;
}
var 上传 = new UploadOperation ();
//尝试这个压缩文件,但它不起作用,显然不适合该对象
// file = file.slice(0,Math.round(file.size / 2));
上传
start uri file );
//在全局数组中保持上传操作。
uploadOperations
push upload );
});
}



然后其余部分上传文件。我尝试添加.slice但它不起作用(我猜测因为文件是一个对象而不是)而且我不知道如何压缩这种类型的文件对象。我似乎无法在msdn或windows
dev论坛上找到任何示例或建议,我可以在服务器上显然重新调整照片,但我宁愿用户不是他们的文件上传时间比他们要长的时间要长。我非常希望能够调整音频和视频文件的大小,如果可能的话......



我需要保存图像才能操作吗?任何建议都会非常感谢!




解决方案

您可以使用BitmapEncoder以较小的尺寸重新编码位图.S ee如何编辑图像(HTML)
的基础知识。


I would like to resize an image picked from the gallery of the phone before uploading it via background transfer so far I have:-

filePicker.pickSingleFileAsync().then(function (file) {
                            uploadSingleFileAsync(uri, file);
                        }).done(null, displayException);

function uploadSingleFileAsync(uri, file) {
                    if (!file) {
                        displayError("Error: No file selected.");
                        return;
                    }
                    return file.getBasicPropertiesAsync().then(function (properties) {
                        if (properties.size > maxUploadFileSize) {
                            displayError("Selected file exceeds max. upload file size (" + (maxUploadFileSize / (1024 * 1024)) +
                                " MB).");
                            return;
                        }
                        var upload = new UploadOperation();
                        //tried this to compress the file but it doesnt work obviously not right for the object
                        //file = file.slice(0, Math.round(file.size / 2));
                        upload.start(uri, file);
                        // Persist the upload operation in the global array.
                        uploadOperations.push(upload);
                    });
                }

and the rest then uploads the file. I tried adding in .slice but it doesn't work (im guessing because file is an object rather than) and I'm not sure how to compress this type of file object. I can't seem to find any examples or advice on msdn or the windows dev forums, I can obviously resize the photos once they are on the server but I would rather users are not waiting longer than they have to for their files to upload. I would quite like to be able to resize audio and video files as well if that is at all possible...

Do I need to save the image before I can manipulate it? Any advice would be greatly appreciated!


解决方案

You can use a BitmapEncoder to reencode the bitmap at a smaller size. See How to edit an image (HTML) for the basics.


这篇关于在html / js windows universal app 8.1中通过后台传输上传之前调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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