问题描述
对不起,问个简单的问题:
Excuse me, quick question:
我有这个视频流程序,我接收数据包,将它们转换为 byte[] ,然后转换为位图,然后将它们显示在屏幕上:
I have this routine of video stream, where I receive packets, convert them to byte[] ,then to bitmaps, then display them on the screen:
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(我不知道如何使用),但首先,我需要准备一个有序图像的目录,然后将其转换为视频文件.这样做我将在内部保存所有图像,并且我正在使用 this answer 保存每张图片:
Now, I want to implementing a Recording feature. Suggestions say I need to use FFmpeg (which I have no idea how) but first, I need to prepare a directory of the ordered images to then convert it to a video file. Do do that I will save all the images internally, and I am using this answer to save each image:
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();
}
但我似乎无法在我的设备上找到目录(实际查看我是否成功创建目录)///data/data/yourapp/app_data/imageDir 的路径在哪里
确切位置?
But I can't seem to find the directory on my device (To actually see if I succeeded in creating the directory) Where is // path to /data/data/yourapp/app_data/imageDir
located exactly?
推荐答案
ContextWrapper
的getDir
方法会自动创建imageDir
目录,如果根据 文档.此外,除非您具有 root 访问权限,否则您无法访问应用程序代码之外的 /data
目录中的任何内容.如果您想查看保存在此目录中的图像,可以在命令提示符下运行 adb
工具将图像移动到可公开访问的目录中:
The getDir
method of ContextWrapper
will automatically create the imageDir
directory if it does not already exist according to the docs. Additionally, you cannot access anything in the /data
directory outside of your application code unless you have root access. If you would like to view the images you saved in this directory, you can run the adb
tool in a command prompt to move the images into a publicly accessible directory:
adb shell run-as com.your.packagename cp -r /data/data/com.your.packagename/app_data/imageDir /sdcard/imageDir
请注意,run-as
命令仅在您的应用程序可调试时才有效.
Note that the run-as
command will only work if your application is debuggable.
您可以将 /sdcard/imageDir
替换为您在设备上有权访问的任何目录.如果您想随后将文件从设备上移到您的机器上,您可以使用 adb pull
从公共目录中拉出文件:
You can replace /sdcard/imageDir
with any directory you have permission to access on the device. If you would like to subsequently move the files off the device and onto your machine, you can use adb pull
to pull the files from the public directory:
adb pull /sdcard/myDir C:UsersDesktop
再次,将 /sdcard/myDir
和 C:UsersDesktop
替换为适当的源目录和目标目录.
Again, replace /sdcard/myDir
and C:UsersDesktop
with the appropriate source and destination directories.
这篇关于我在哪里可以找到 Android 中保存的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!