【发布时间】:2019-04-17 14:12:15
【问题描述】:
下午好,在我的应用程序中,我使用手机摄像头拍摄视频,然后启动此视频,谢谢
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
{
Surface s = new Surface(surface);
try
{
mp = new MediaPlayer();
mp.setDataSource(getVideoFilePath());
mp.setSurface(s);
mp.prepare();
mp.setOnBufferingUpdateListener(this);
mp.setOnCompletionListener(this);
mp.setOnPreparedListener(this);
mp.setOnVideoSizeChangedListener(this);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
setPreviewSize(true);
mp.start();
}
catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我实现了一种截取屏幕截图并将其保存到图库的方法,
public void getBitmap(TextureView vv)
{
String mPath = getAndroidImageFolder().getAbsolutePath() + "/" + new SimpleDateFormat("yyyyMM_dd-HHmmss").format(new Date()) + "cameraRecorder.png";
Toast.makeText(getApplicationContext(), "Capturing Screenshot: " + mPath, Toast.LENGTH_SHORT).show();
Bitmap bm = vv.getBitmap();
if(bm == null)
Log.e(TAG,"bitmap is null");
OutputStream fout = null;
File imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bm.compress(Bitmap.CompressFormat.PNG, 90, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
Log.e(TAG, "FileNotFoundException");
e.printStackTrace();
} catch (IOException e) {
Log.e(TAG, "IOException");
e.printStackTrace();
}
}
但是截图没有出现在图库中,敲出一个错误。 这就是 Logcat 中产生的内容
E/TextureViewActivity: FileNotFoundException
11-14 15:25:09.961 4143-4143/com. W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/201811_14-152509cameraRecorder.png: open failed: ENOENT (No such file or directory)
11-14 15:25:09.971 4143-4143/com. W/System.err: at libcore.io.IoBridge.open(IoBridge.java:452)
11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
11-14 15:25:09.971 4143-4143/com. W/System.err: at com.
camera.VideoProcessor.getBitmap(VideoProcessor.java:245)
11-14 15:25:09.971 4143-4143/com. W/System.err: at com.camera.VideoProcessor.onClick(VideoProcessor.java:369)
这里关于代码的哪一部分敲出错误
at com.camera.VideoProcessor.getBitmap(VideoProcessor.java:247) -> fout = new FileOutputStream(imageFile);
非常感谢您的帮助)
【问题讨论】:
标签: android file screenshot fileoutputstream