Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BMP Preview Error #105

Open
wuyou201400 opened this issue Oct 14, 2014 · 2 comments
Open

BMP Preview Error #105

wuyou201400 opened this issue Oct 14, 2014 · 2 comments

Comments

@wuyou201400
Copy link

I Want to Preview the Bmp Picture,But Work Not .Why?Thanks.My Code Is:

function previewImage(file, callback) {
    if (!file || !/image\//.test(file.type)) return; 
    if (file.type == 'image/gif') {//gif使用FileReader进行预览,因为mOxie.Image只支持jpg和png
        var fr = new mOxie.FileReader();
        fr.onload = function () {
            callback(fr.result);
            fr.destroy();
            fr = null;
        }
        fr.readAsDataURL(file.getSource());
    } else {
        var preloader = new mOxie.Image();
        preloader.onload = function () {
            preloader.downsize(300, 300); //先压缩一下要预览的图片,宽300,高300
            var imgsrc = preloader.type == 'image/jpeg' ? preloader.getAsDataURL('image/jpeg', 80) : preloader.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
            callback && callback(imgsrc); //callback传入的参数为预览图片的url
            preloader.destroy();
            preloader = null;
        };
        preloader.load(file.getSource());
    }
}
@jayarjo
Copy link
Contributor

jayarjo commented Dec 21, 2014

Currently only jpegs and pngs are considered to be images. Maybe its time to recap this.

@liuyidi
Copy link

liuyidi commented Jun 17, 2016

you can change file.type ,for example

function previewImage(file, callback) {
    if (!file || !/image\//.test(file.type)) return; 
    if (file.type == ('image/bmp' || 'image/gif') ) {//gif使用FileReader进行预览,因为mOxie.Image只支持jpg和png
        var fr = new mOxie.FileReader();
        fr.onload = function () {
            callback(fr.result);
            fr.destroy();
            fr = null;
        }
        fr.readAsDataURL(file.getSource());
    } else {
        var preloader = new mOxie.Image();
        preloader.onload = function () {
            preloader.downsize(300, 300); //先压缩一下要预览的图片,宽300,高300
            var imgsrc = preloader.type == 'image/jpeg' ? preloader.getAsDataURL('image/jpeg', 80) : preloader.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
            callback && callback(imgsrc); //callback传入的参数为预览图片的url
            preloader.destroy();
            preloader = null;
        };
        preloader.load(file.getSource());
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants