本文介绍了我在哪里可以找到保存的图像在Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起,快速问题:
我有这个视频流程序,我收到数据包,将它们转换成byte [],然后进行位图显示他们在屏幕上:
dsocket.receive(packetReceived); // receive packet
byte [] buff = packetReceived.getData(); //将数据包转换为byte []
final Bitmap ReceivedImage = BitmapFactory.decodeByteArray(buff,0,buff.length); //将byte []转换为位图图像
runOnUiThread(new Runnable()
{
@Override
public void run()
{
//这是在主(UI)线程执行
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 );
//路径到/ data / data / yourapp / app_data / imageDir
文件MyDirectory = cw.getDir(imageDir,Context.MODE_PRIVATE);
//创建imageDir
文件MyPath = new File(MyDirectory,Image+ counter +.jpg);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(MyPath);
//在BitMap对象上使用compress方法将图像写入OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG,100,fos);
} catch(Exception e){
e.printStackTrace();
} finally {
try {
fos.close();
} catch(IOException e){
e.printStackTrace();
}
}
//返回MyDirectory.getAbsolutePath();
}
但我似乎找不到我的设备上的目录(实际上看看我是否成功创建了目录)
//路径到/ data / data / yourapp / app_data / imageDir div class =h2_lin>解决方案 getDir
方法 ContextWrapper
将自动创建根据。此外,您无法访问应用程序代码之外的 / data
目录中的任何内容,除非您具有根访问权限。如果您想查看保存在此目录中的图像,可以在命令提示符下运行 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
和 C:\Users\Desktop
具有相应的源目录和目标目录。
Excuse me, quick question:
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);
}
});
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();
}
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?
解决方案
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
Note that the run-as
command will only work if your application is debuggable.
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:\Users\Desktop
Again, replace /sdcard/myDir
and C:\Users\Desktop
with the appropriate source and destination directories.
这篇关于我在哪里可以找到保存的图像在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!