首页 文章 精选 留言 我的

精选列表

搜索[android jetpack],共10000篇文章
优秀的个人博客,低调大师

Android JavaCV(图片转视频)

JavaCV JavaCpp 如果下载不了,可以下载此处 1. 使用 注意:存储8张源图的路径是"/sdcard/ScreenRecord/temp/", 存储输出的视频文件路径为"/sdcard/ScreenRecord/",事先应现在"/sdcard/ScreenRecord/temp/"放置8张图片,当然本例中是8张,可以根据自己的需求变化 public class MainActivity extends AppCompatActivity { public static final String IMAGE_TYPE = ".png"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void start(View view) { imageToMp4(); } /** * 图片转视频 */ private void imageToMp4() { // 生成的新文件名 String newFileName = "test_" + System.currentTimeMillis() + ".mp4"; // 保存的路径 String temp = null; final double frameRate = 5; try { temp = new FileUtils().getSDCardRoot() + "ScreenRecord" + File.separator + newFileName; } catch (FileUtils.NoSdcardException e1) { e1.printStackTrace(); } final String savePath = temp; new Thread() { @Override public void run() { Log.d("test", "开始将图片转成视频啦...frameRate=" + frameRate); try { // 临时文件路径即存储源图片的路径 String tempFilePath = new FileUtils().getSDCardRoot() + "ScreenRecord/temp" + File.separator; Log.i("test", "tempFilePath=" + tempFilePath); Bitmap testBitmap = BitmapFactory.decodeFile(tempFilePath + "head1" + MainActivity.IMAGE_TYPE); //创建一个记录者 FFmpegFrameRecorder recorder = new FFmpegFrameRecorder( savePath, testBitmap.getWidth(), testBitmap.getHeight()); // 设置视频格式 recorder.setFormat("mp4"); // 录像帧率 recorder.setFrameRate(frameRate); // 记录开始 recorder.start(); int index = 0; while (index < 8) { // 获取图片--图片格式为head1.png,head2.png...head8.png opencv_core.IplImage image = cvLoadImage(tempFilePath + "head" + index + MainActivity.IMAGE_TYPE); recorder.record(image); index++; } Log.d("test", "录制完成...."); // 录制结束 recorder.stop(); } catch (FileUtils.NoSdcardException | FrameRecorder.Exception e) { e.printStackTrace(); } } }.start(); } } FileUtils.java public class FileUtils { private String SDCardRoot; private static boolean isCardExist; public FileUtils() throws NoSdcardException { getSDCardRoot(); } public String getSDCardRoot() throws NoSdcardException{ if(isCardExist()){ SDCardRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator; }else{ throw new NoSdcardException(); } return SDCardRoot; } public static boolean isCardExist(){ isCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)?true:false; return isCardExist; } public File createFileInSDCard(String fileName, String dir) throws IOException { File file = new File(SDCardRoot + dir + File.separator + fileName); if(!file.exists()){ file.getParentFile().mkdirs(); file.createNewFile(); } return file; } public File creatSDDir(String dir) { File dirFile = new File(SDCardRoot + dir + File.separator); if(!dirFile.exists()){ dirFile.mkdirs(); } return dirFile; } public boolean filterFileExist(String path, String filter) { File file = new File(SDCardRoot + path + File.separator); if (file.exists() && file.isDirectory()) { String[] fileNames = file.list(new FilenameFilter() { public boolean accept(File dir, String filename) { return filename.endsWith(".png"); } }); if (fileNames.length > 0) { return true; } else { return false; } } else { return false; } } /** * */ public boolean isFileExist(String fileName, String path) { File file = new File(SDCardRoot + path + File.separator + fileName); return file.exists(); } public File getFile(String fileName,String path){ File file = new File(SDCardRoot + path + File.separator + fileName); return file; } public void deleteFile(String fileName, String path) { File file = new File(SDCardRoot + path + File.separator + fileName); boolean result = file.delete(); } public void closeInputStream(InputStream inputStream){ if(inputStream!=null){ try { inputStream.close(); } catch (IOException e) { Log.e("error", "close failed"); e.printStackTrace(); } } } public class NoSdcardException extends Exception{ } /** * 删除文件夹中的内容,不删除文件夹本身 * @param path */ public static void deleteDirectoryContent(String path){ Log.w("test","deleteDirectory.."+path); File file=new File(path); if(!file.exists()){ return; } String fPath=file.getAbsolutePath(); if(file.isDirectory()){ String[] files=getDirectoryFiles(path); if(files==null){ deleteFile(path); return; } for(String str:files){ str=fPath+"/"+str; file=new File(str); if(file.isDirectory()){ deleteDirectory(str); }else if(file.isFile()){ deleteFile(str); } } // deleteFile(path); }else if(file.isFile()){ deleteFile(path); } } /** * 删除文件夹中的内容 * @param path */ public static void deleteDirectory(String path){ Log.w("test","deleteDirectory.."+path); File file=new File(path); if(!file.exists()){ return; } String fPath=file.getAbsolutePath(); if(file.isDirectory()){ String[] files=getDirectoryFiles(path); if(files==null){ deleteFile(path); return; } for(String str:files){ str=fPath+"/"+str; file=new File(str); if(file.isDirectory()){ deleteDirectory(str); }else if(file.isFile()){ deleteFile(str); } } deleteFile(path); }else if(file.isFile()){ deleteFile(path); } } /** * 删除指定路径的文件 * @param filePath * 文件路径 */ public static void deleteFile(String filePath){ Log.w("test","deleteFile:filePath="+filePath); if(filePath==null){ return; } File file=new File(filePath); if(file.exists()){ file.delete(); } } /** * 获取文件夹下面的所有文件 * @param path * @return */ public static String[] getDirectoryFiles(String path){ if(path==null){ return null; } File file=new File(path); if(!file.exists()){ return null; } String[] files=file.list(); if(files==null || files.length<=0){ return null; } return files; } }

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册