安卓中webp格式图片转换格式上传服务器(包含.jar和.so文件)
来源:互联网 发布:火箭 模拟软件 编辑:程序博客网 时间:2024/06/07 01:39
/** * Created by pc on 2017/8/24. * 转换图片格式为webp的图片、这种格式要么服务器处理、要么客户端本地处理、否则上传不支持
http://download.csdn.net/download/dsb2008dsb/9813264(.jar和.so下载地址) */public class WebpImageToPngImageUtils { static { System.loadLibrary("webp"); } public static byte[] loadFileAsByteArray(String filePath) { File file = new File(filePath); byte[] data = new byte[(int) file.length()]; try { FileInputStream inputStream; inputStream = new FileInputStream(file); inputStream.read(data); inputStream.close(); } catch (Exception e) { e.printStackTrace(); } return data; } public static Bitmap webpToBitmap(byte[] encoded) { int[] width = new int[]{0}; int[] height = new int[]{0}; byte[] decoded = libwebp.WebPDecodeARGB(encoded, encoded.length, width, height); //byte[] decoded = libwebp.WebPDecodeARGB(encoded, encoded.length, width, height); int[] pixels = new int[decoded.length / 4]; ByteBuffer.wrap(decoded).asIntBuffer().get(pixels); return Bitmap.createBitmap(pixels, width[0], height[0], Bitmap.Config.ARGB_8888); } public static File changeImageType(File file) { File newFile; //webp图片格式判断代码: BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(file.getAbsolutePath(), options); String type = options.outMimeType; if (type.equals("image/webp")) {// Bitmap转png代码: Bitmap bp = webpToBitmap(loadFileAsByteArray(file.getAbsolutePath())); String c = file.getParent(); newFile = new File(c + File.separator + System.currentTimeMillis() + ".png"); if (newFile.exists()) { newFile.delete(); } FileOutputStream out; try { out = new FileOutputStream(newFile); if (bp.compress(Bitmap.CompressFormat.PNG, 90, out)) { out.flush(); out.close(); } return newFile; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return file; }}
阅读全文
0 0
- 安卓中webp格式图片转换格式上传服务器(包含.jar和.so文件)
- webp格式图片转换问题解决方法
- Android中将webp格式图片转换为png和jpg(续)
- webp格式图片
- webp格式图片调研
- webp格式的图片
- WebP格式图片应用
- Android将webp格式图片转换为png格式方法
- 基于webp格式的图片转换问题与port的
- 分享两个转换webp格式图片的工具
- 扒一扒“WEBP格式”的图片
- WebP 探寻之路 --- SDWebImage支持webp格式的图片
- Android兼容性问题 -- WebP格式图片解码失败
- 在sdwebimage中加载webp格式图片。
- 在WebView中使用webp格式图片
- 如何创建webp格式的图片
- iOS 全面支持 webp格式图片
- webP 格式图片在 iOS 中的应用
- 优秀前端工程师简历收集
- Which One Is Better: 2.4 GHz or 5 GHz?
- Python绘图与数据处理
- The Same Game POJ
- vcenter web client中向windows虚拟机键入ctrl+alt+delete
- 安卓中webp格式图片转换格式上传服务器(包含.jar和.so文件)
- java connect oracle Error ORA-12505
- Python——爬虫
- Netty 初步
- 小程序文档整理之 -- 事件
- java线程原子锁
- Python爬虫数据存储MySQL【1】连接方式
- 写个app, 性能很捉急
- IDEA常用配置