当前位置: 首页 > news >正文

Android平台RTSP|RTMP播放端实时快照保存JPG还是PNG?

JPG还是PNG?

实际上,在前几天的blog,我们有从压缩方式、图像质量、透明效果、可编辑性等各方面做过差异化的介绍。

  • 压缩方式:JPG是一种有损压缩格式,通过丢弃图像数据来减小文件大小,因此可能会损失一些图像细节和质量。而PNG使用的是无损压缩格式,它不会丢失任何原始图像数据,从而保持了图像的完整性和质量。
  • 图像质量:由于压缩方式的不同,JPG在压缩后会牺牲一部分图像数据,因此在图像质量上可能存在损失,例如可能会出现锯齿状边缘或颜色失真。相比之下,PNG的无损压缩可以保证原图像数据的完整性,其256个透明层次的设定可以使图片边缘平滑融合,从而消除图片锯齿边缘。
  • 透明效果:PNG支持透明度,可以用作背景透明的图片,而JPG则不支持透明效果。因此,如果你需要制作半透明的图像或者需要背景透明的图片,PNG是一个更好的选择。
  • 可编辑性:JPG是一种不可编辑的图片格式,一旦被保存为JPG格式,就无法进行修改。而PNG是一种可编辑的图片格式,可以通过图像编辑软件(如Photoshop)进行修改、编辑和重新保存。例如,你可以改变PNG图片中的文字样式、线条等元素。

Android平台RTSP|RTMP播放器快照

Android平台RTSP|RTMP播放器截图,我们都是直接保存png图片,新的接口,jpg和png均支持。

原接口:

	/*** 请使用新的CaptureImage接口, 这个接口只能保存为PNG图片, 不再推荐使用* Save current image during playback stream(实时快照)** @param handle: return value from SmartPlayerOpen()** @param imageName: image name, which including fully path, "/sdcard/daniuliveimage/daniu.png", etc.** @return {0} if successful*/public native int SmartPlayerSaveCurImage(long handle, String imageName);

值得注意的是,原接口如果需要截图,还需要调用SmartPlayerSaveImageFlag()。

新的接口,我们设计如下:

	/*** 新的截图接口, 支持JPEG和PNG两种格式* @param compress_format: 压缩格式, 0:JPEG格式, 1:PNG格式, 其他返回错误* @param quality: 取值范围:[0, 100], 值越大图像质量越好, 仅对JPEG格式有效, 若是PNG格式,请填100* @param file_name: 图像文件名, 例如:/dirxxx/test20231113100739.jpeg, /dirxxx/test20231113100739.png* @param user_data_string: 用户自定义字符串* @return {0} if successful*/public native int CaptureImage(long handle, int compress_format, int quality, String file_name, String user_data_string);

如何调用?

        btnCaptureImage.setOnClickListener(new Button.OnClickListener() {@SuppressLint("SimpleDateFormat")public void onClick(View v) {if (0 == playerHandle)return;if (null == capture_image_date_format_)capture_image_date_format_ = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");String timestamp = capture_image_date_format_.format(new Date());String imageFileName = timestamp;String image_path = imageSavePath + "/" + imageFileName;int quality;boolean is_jpeg = true;if (is_jpeg) {image_path += ".jpeg";quality = 100;}else {image_path += ".png";quality = 100;}int capture_ret = libPlayer.CaptureImage(playerHandle,is_jpeg?0:1, quality, image_path, "test cix");Log.i(TAG, "capture image ret:" + capture_ret + ", file:" + image_path);}});

截图成功,对应的event回调如下:

    class EventHandeV2 implements NTSmartEventCallbackV2 {@Overridepublic void onNTSmartEventCallbackV2(long handle, int id, long param1,long param2, String param3, String param4, Object param5) {String player_event = "";switch (id) {case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:player_event = "开始..";break;case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:player_event = "连接中..";break;case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:player_event = "连接失败..";break;case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:player_event = "连接成功..";break;case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:player_event = "连接断开..";break;case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_STOP:player_event = "停止播放..";break;case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:player_event = "分辨率信息: width: " + param1 + ", height: " + param2;break;case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:player_event = "收不到媒体数据,可能是url错误..";break;case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_SWITCH_URL:player_event = "切换播放URL..";break;case NTSmartEventID.EVENT_DANIULIVE_ERC_PLAYER_CAPTURE_IMAGE:player_event = "快照: " + param1 + " 路径:" + param3;if (param1 == 0)player_event = player_event + ", 截取快照成功";elseplayer_event = player_event + ", 截取快照失败";if (param4 != null && !param4.isEmpty())player_event += (", user data:" + param4);break;..........}if (player_event.length() > 0) {Log.i(TAG, player_event);Message message = new Message();message.what = PLAYER_EVENT_MSG;message.obj = player_event;handler.sendMessage(message);}}}

总结

大家都知道,JPG(JPEG)是有损压缩格式,保持图片质量的同时,通过牺牲一部分图像信息来减小文件尺寸。所以,JPG适合用于存储照片和其他复杂的图像。JPG格式的文件通常比PNG格式的文件小,因此在网络传输和存储时更为方便。

http://www.lryc.cn/news/283507.html

相关文章:

  • 【人工智能】之深入了解嵌入模型中的 Token:NLP 中的语义之旅(1)
  • UML-实现图(组件图和部署图)
  • 苹果Find My可查找添加32件物品,伦茨科技ST17H6x芯片加速产品赋能
  • postman后端测试时invalid token报错+token失效报错解决方案
  • 使用 mybatis-plus 的mybaits的一对多时, total和record的不匹配问题
  • SpringCloud之Nacos
  • 小封装高稳定性振荡器 Sg2520egn / sg2520vgn, sg2520ehn / sg2520vhn
  • 使用 Apache POI 更新/覆盖 特定的单元格
  • Spring Boot整合MyBatis-Plus
  • springboot项目之AOP角色权限的判断
  • Twincat PLC 跳出循环
  • 【Leetcode】277.搜寻名人
  • 小白数学建模 Mathtype 7.7傻瓜式下载安装嵌入Word/WPS以及深度使用教程
  • Linux之which和find
  • MySQL 常规操作指南
  • Rocketmq rust版本-开篇
  • springboot3+springsecurity6集成druid启动报错
  • golang面试题大全
  • Google 在裁员的路上一路狂奔
  • 橘子学K8S04之重新认识Docker容器
  • Day31- 贪心算法part05
  • 基于springboot+vue的蜗牛兼职网的设计与实现系统(前后端分离)
  • 【音视频原理】图像相关概念 ② ( 帧率 | 常见帧率标准 | 码率 | 码率单位 )
  • CSS Position总结:定位属性的实战技巧
  • python基础系列二-函数
  • Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用短曝光功能(C#)
  • 提升开发效率,Fiddler Everywhere for Mac助您解决网络调试难题
  • JVM工作原理与实战(十九):运行时数据区-方法区
  • webassembly003 whisper.cpp的项目结构CMakeLists.txt
  • 克魔助手工具详解、数据包抓取分析、使用教程