[英]Android Image Not saving to sdcard
按下捕获Button
,图像应保存在SD卡中,它正在拍摄快照但不保存图像,那么如何将捕获按钮放在我想要的任何地方? 我在Imageview
有一个叠加层,我需要将按钮放在叠加层上。
int图片回调,请使用这样的
jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
camera.startPreview();
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(
"/mnt/sdcard/myphoto.jpg");
outStream.write(data);
outStream.close();
Log.d("Log", "onPictureTaken - wrote bytes: " + data.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Log.d("Log", "onPictureTaken - jpeg");
}
};
使用此选项将图像存储在SD卡中
public void save(Bitmap image)
{
File sdcard = Environment.getExternalStorageDirectory();
File f = new File (sdcard, imagename);
FileOutputStream out=null;
try {
out = new FileOutputStream(f);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
image.compress(Bitmap.CompressFormat.PNG, 90, out);
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
stream=new ByteArrayOutputStream();
temBitmap=Bitmap.createBitmap(bmp);
temBitmap.compress(Bitmap.CompressFormat.JPEG,100, stream);
path+=String.format(
getString(R.string._sdcard_d_jpg),
System.currentTimeMillis());
outStream = new FileOutputStream(path+extension); // <9>
outStream.write(stream.toByteArray());
outStream.close();
以这种方式更改上面的代码段:
path+=String.format(
getString(R.string._sdcard_d_jpg),
System.currentTimeMillis());
outStream = new FileOutputStream(path+extension); // <9>
temBitmap=Bitmap.createBitmap(bmp);
temBitmap.compress(Bitmap.CompressFormat.JPEG,100, outStream);
outStream.close();
temBitmap.recycle()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.