递归火山软件开发平台

标题: 开源 webp绘制格式图转换PNG,JPG[webp格式转换] [打印本页]

作者: ゞ情非得已Sky    时间: 2024-5-28 11:02
标题: 开源 webp绘制格式图转换PNG,JPG[webp格式转换]
本帖最后由 ゞ情非得已Sky 于 2024-5-28 11:26 编辑

(, 下载次数: 35)
忘了加返回值  已补上


<火山程序 类型 = "通常" 版本 = 1 />

方法 webp到图像 <公开 静态 类型 = 逻辑型 折叠 折叠2
        @java.导入 = "android.graphics.BitmapFactory\nandroid.graphics.Bitmap\njava.io.File\njava.io.FileOutputStream"
        @禁止流程检查 = 真>
参数 webp完整路径 <类型 = 文本型 注释 = "如:/sdcard/测试.webp">
参数 输出路径 <类型 = 文本型 注释 = "如:/sdcard/测试.png">
参数 格式 <类型 = 整数 注释 = "0.png   1.JPEG  2.WEBP" @默认值 = 0>
{
    @ Bitmap bitmap = BitmapFactory.decodeFile(@<webp完整路径>);
    @ File outputFile = new File(@<输出路径>);
    @ boolean compressResult = false;
    开始俘获异常 ()
    {
        @ FileOutputStream out = new FileOutputStream(outputFile);
        @ int gs=@<格式>;
        @ if(gs==0){;
        {
            @ compressResult=bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        }
        @ }else if(gs==1){;
        @ compressResult=bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        @ }else if(gs==2){;
        @ compressResult=bitmap.compress(Bitmap.CompressFormat.WEBP, 100, out);
        @ };
        @ out.flush();
        @ out.close();
        @ if (compressResult && outputFile.length() > 0) {
        @ return true;
        @ }
    }
    俘获所有异常 ()
    @ return false;
}




作者: kingsoft    时间: 2024-5-29 15:44
点赞支持!
作者: sexwolf    时间: 2024-5-30 21:45
这个抬升奥勒





欢迎光临 递归火山软件开发平台 (https://bbs.voldp.com/) Powered by Discuz! X3.4