图像存储在内部存储器中的android [英] store an image in internal storage in android
问题描述
我现在工作的应用程序,启动相机和拍照,我没有用相机活动,但我写了我的相机应用程序,我想保存拍摄的图像在手机内部存储的文件夹,名为temPic
下面code生成的文件夹和图像,但是当我检查了tempPic我发现一个图像称为image1.jpg,它的大小是461115(我试图存储SD卡目录中的形象,它是相同的大小),但是当我双击了它一个黑色的形象出现,而不是采取的一项虽然在SD卡我打开它!
FileManipulator FILEFORMAT =新FileManipulator(
getApplicationContext());
字符串路径= fileFormat.createFolder_PStrg(tempPic)+/image1.jpg;
档案文件=新的文件(路径);
乌里outputFileUri = Uri.fromFile(文件);
的OutputStream imageFileOS;
尝试 {
imageFileOS = getContentResolver()openOutputStream(outputFileUri)。
imageFileOS.write(为arg0);
imageFileOS.flush();
imageFileOS.close();
Toast.makeText(AndroidCamera.this,
file.length()+,
Toast.LENGTH_LONG).show();
Toast.makeText(AndroidCamera.this,
图片保存:+ outputFileUri.toString()
Toast.LENGTH_LONG).show();
}赶上(FileNotFoundException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}赶上(IOException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
camera.start preVIEW();
我不知道这是否可以帮助你,但我这是怎么将文件保存到SD卡和它的作品。
公共无效saveToSD(位图outputImage){
文件storagePath =新的文件(Environment.getExternalStorageDirectory()+/ MyPhotos /);
storagePath.mkdirs();
文件MYIMAGE =新的文件(storagePath,Long.toString(System.currentTimeMillis的())+.JPG);
尝试 {
FileOutputStream中出=新的FileOutputStream(MYIMAGE);
outputImage.com preSS(Bitmap.Com pressFormat.JPEG,80出);
了out.flush();
out.close();
}赶上(例外五){
e.printStackTrace();
}
}
I am working now on application that start the camera and take a photo, I didn't use camera activity, but I wrote my camera app and I want to save the taken image in the internal phone storage in folder called "temPic"
The following code generate the folder and the image, but when I checked the tempPic I found an image called image1.jpg and it's size is 461115 ( I tried to store the image in SDcard directory and it is the same size), but when I double clicked it a black image appeared, not the taken one although in SDcard I opened it !!!
FileManipulator fileFormat = new FileManipulator(
getApplicationContext());
String path = fileFormat.createFolder_PStrg("tempPic") + "/image1.jpg";
File file = new File(path);
Uri outputFileUri = Uri.fromFile(file);
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(outputFileUri);
imageFileOS.write(arg0);
imageFileOS.flush();
imageFileOS.close();
Toast.makeText(AndroidCamera.this,
file.length()+"",
Toast.LENGTH_LONG).show();
Toast.makeText(AndroidCamera.this,
"Image saved: " + outputFileUri.toString(),
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
camera.startPreview();
I don't know if this can help you but this is how I save a file to the SD card and it works.
public void saveToSD(Bitmap outputImage){
File storagePath = new File(Environment.getExternalStorageDirectory() + "/MyPhotos/");
storagePath.mkdirs();
File myImage = new File(storagePath, Long.toString(System.currentTimeMillis()) + ".jpg");
try {
FileOutputStream out = new FileOutputStream(myImage);
outputImage.compress(Bitmap.CompressFormat.JPEG, 80, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
这篇关于图像存储在内部存储器中的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!