打扰一下,快速提问:
我有这样的视频流例程,我接收数据包,将它们转换为 byte[] ,然后转换为位图,然后将它们显示在屏幕上:
dsocket.receive(packetReceived); // receive packet
byte[] buff = packetReceived.getData(); // convert packet to byte[]
final Bitmap ReceivedImage = BitmapFactory.decodeByteArray(buff, 0, buff.length); // convert byte[] to bitmap image
runOnUiThread(new Runnable()
{
@Override
public void run()
{
// this is executed on the main (UI) thread
imageView.setImageBitmap(ReceivedImage);
}
});
现在,我想实现一个录音功能。建议说我需要使用 FFmpeg (我不知道如何使用),但首先,我需要准备一个订购图像的目录,然后将其转换为视频文件。这样做我将在内部保存所有图像,并且我正在使用这个答案保存每个图像:
if(RecordVideo && !PauseRecording) {
saveToInternalStorage(ReceivedImage, ImageNumber);
ImageNumber++;
}
else
{
if(!RecordVideo)
ImageNumber = 0;
}
// ...
private void saveToInternalStorage(Bitmap bitmapImage, int counter){
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File MyDirectory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
File MyPath = new File(MyDirectory,"Image" + counter + ".jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(MyPath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//return MyDirectory.getAbsolutePath();
}
但我似乎无法在我的设备上找到该目录(要实际查看我是否成功创建了该目录)在哪里// path to /data/data/yourapp/app_data/imageDir
具体位于?
The getDir
的方法ContextWrapper
会自动创建imageDir
目录(如果根据以下内容尚不存在)docs。此外,您无法访问/data
除非您具有 root 访问权限,否则您的应用程序代码之外的目录。如果您想查看保存在该目录中的图像,您可以运行adb
命令提示符中的工具将图像移动到可公开访问的目录中:
adb shell run-as com.your.packagename cp -r /data/data/com.your.packagename/app_data/imageDir /sdcard/imageDir
请注意,run-as
仅当您的应用程序可调试时,命令才有效。
您可以更换/sdcard/imageDir
与您有权访问设备上的任何目录。如果您想随后将文件从设备移到您的计算机上,您可以使用adb pull
从公共目录中提取文件:
adb pull /sdcard/myDir C:\Users\Desktop
再次更换/sdcard/myDir
and C:\Users\Desktop
具有适当的源目录和目标目录。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)