aardio 文档

aardio 范例: WebView2 - WebP 图像转 JPG 格式

//转换 WebP 图像
import fsys;
import process;
import win.ui;
/*DSG{{*/
var winform = win.form(text="WebView2 - WebP 图像转 JPG 格式";right=966;bottom=622;)
winform.add(
btnCallJavaScript={cls="button";text="转换图像";left=615;top=537;right=869;bottom=606;color=14120960;db=1;dr=1;font=LOGFONT(h=-14);note="WebP 图像转 JPG 格式";z=2;};
static={cls="static";left=8;top=6;right=956;bottom=503;db=1;dl=1;dr=1;dt=1;z=1;};

)
/*}}*/

import web.view;
var wb = web.view(winform.static);

import inet.urlData;
wb.external = {
    OnConvertCompleted = function(dataUrl,savePath){
        var data,mime = inet.urlData.parse(dataUrl);
        string.save(savePath,data);


        process.exploreSelect(savePath);
    } 
}

wb.html = /**
<!DOCTYPE html><html>
<head><meta charset="utf-8" /></head>
<body>  
<canvas id="canvas" ></canvas>
<script> 

    let canvas = document.getElementById("canvas")

    window.convertImage = function(dataUrl,savePath){
        let img = new Image();
        img.src = dataUrl;
        img.onload = function() {
            canvas.setAttribute("width", this.width);
            canvas.setAttribute("height", this.height);
            canvas.getContext("2d").drawImage(this, 0, 0);
            canvas.toBlob(function(blob) {

            const reader = new FileReader();
            reader.onloadend = function() {
                aardio.OnConvertCompleted(reader.result,savePath);
            }
            reader.readAsDataURL(blob);

            }, `image/jpeg`, 0.1)
        };
    } 

</script>

</body> 
**/

import fsys.dlg;
winform.btnCallJavaScript.oncommand = function(id,event){
    var path = fsys.dlg.open("*.webp|*.webp||","请指定要转换的图像");
    if(!path) return;

    var url = inet.urlData(,path)
    wb.xcall("convertImage",url,fsys.path.replaceExt(path,".jpg"));
}

/*
也可以这样转换:

import process.ffmpeg;
var ffmpeg = process.ffmpeg("/",
    "-y","-i","~/example/Graphics/.gdip.jpg","out.webp");
*/

winform.show();
win.loopMessage();
Markdown 格式