我正在开发一个应用程序,该应用程序要求将视频或图像插入带有一个或多个视频的PNG图像框中,该程序的图像部分运行良好,因为我可以将视图转换为位图并保存它,当我必须保存带有视频的图像框时,我面临的问题就来了,我可以拿起一个视频并将其设置在"视频"视图中,但当试图保存它时,我束手无策。因为没有办法将视图转换为视频。
我的布局:
<androidx.constraintlayout.widget.ConstraintLayout
android:id = "@+id/multiView"
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "1" >
<RelativeLayout
android:id = "@+id/relativeLayout"
android:layout_width = "match_parent"
android:layout_height = "match_parent" />
<ImageView
android:id = "@+id/frame"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:scaleType = "fitXY"
android:src = "@drawable/flowerpower"
app:layout_constraintEnd_toEndOf = "parent"
app:layout_constraintStart_toStartOf = "parent"
app:layout_constraintTop_toTopOf = "parent" />
<FrameLayout
android:id = "@+id/stickerAdd"
android:layout_width = "match_parent"
android:layout_height = "match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout >
约束布局是父视图,它有另一个视图,如PNG图像视图和粘贴视图,用户选择的图像/视频被动态添加到帧空白空间内的位置
以下是我如何保存带有框架的图像:
View view = multiView;
view.setDrawingCacheEnabled ( true );
Bitmap bitmap = Bitmap.createBitmap ( view.getDrawingCache ( ) );
view.setDrawingCacheEnabled ( false );
File localFile = new File ( path , filename );
FileOutputStream outputStream = new FileOutputStream ( localFile );
bitmap.compress ( Bitmap.CompressFormat.JPEG , 100 , outputStream );
outputStream.flush ( );
outputStream.close ( );
MediaScannerConnection.scanFile ( this , new String[] { localFile.getAbsolutePath ( ) } ,
null , ( path1 , uri ) -> {
} );
Toasty.custom ( MainActivity.this , "Image Saved" , null ,
getColor ( R.color.colorPrimary ) , getColor ( R.color.colorAccent ) , Toast.LENGTH_SHORT ,
false , true ).show ( );
有人能帮助我如何保存这个,但作为一个视频
名为FFMPEG的名称是对视频或视频以及多个图像创建、更新或执行某些操作的最佳方式。
您可以通过使用FFMPEG组合图像从多个图像创建视频,也可以使用此功能对视频进行更高级别的修改。
这是android中的面糊库,用于开始使用FFMPEG。这个库在android 10或更高版本中也运行良好。
https://github.com/tanersener/mobile-ffmpeg
这就是的实现
implementation 'com.arthenica:mobile-ffmpeg-full:4.4'
FFMPEG的官方文档:-
FFMPEG官方文档