调用系统照相机的takePicture,回调过来的图片,
// 拍照成功回调函数
private Camera.PictureCallback myPicCallback = new Camera.PictureCallback() { @Override
public void onPictureTaken(byte[] data, Camera camera) { // 将得到的照片进行270度旋转,使其竖直
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
Matrix matrix = new Matrix();
matrix.preRotate(270);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, true); iv.setImageBitmap(bitmap);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date()); // 创建并保存图片文件
File pictureFile = new File(getDir(), "IMG_" + timeStamp + ".jpg");
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
Log.e("Tag","拍照成功");
openFacingFrontCamera();
} catch (Exception error) {
Log.e("Tag","拍照失败:"+error);
Log.i("Tag", "保存照片失败" + error.toString());
error.printStackTrace();
openFacingFrontCamera();
} /* myCamera.stopPreview();
myCamera.release();
myCamera = null;*/
}
};
代码是这样的,在我自己的手机上看着挺正常的,但是放到客户的那种网络一体机,就出问题了,边缘发绿了,关键它用它内置的拍照app进行拍照,出来的照片没问题的,所以就觉着是不是我哪出问题了,求解个大神!!图片就是这样的
// 拍照成功回调函数
private Camera.PictureCallback myPicCallback = new Camera.PictureCallback() { @Override
public void onPictureTaken(byte[] data, Camera camera) { // 将得到的照片进行270度旋转,使其竖直
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
Matrix matrix = new Matrix();
matrix.preRotate(270);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, true); iv.setImageBitmap(bitmap);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date()); // 创建并保存图片文件
File pictureFile = new File(getDir(), "IMG_" + timeStamp + ".jpg");
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
Log.e("Tag","拍照成功");
openFacingFrontCamera();
} catch (Exception error) {
Log.e("Tag","拍照失败:"+error);
Log.i("Tag", "保存照片失败" + error.toString());
error.printStackTrace();
openFacingFrontCamera();
} /* myCamera.stopPreview();
myCamera.release();
myCamera = null;*/
}
};
代码是这样的,在我自己的手机上看着挺正常的,但是放到客户的那种网络一体机,就出问题了,边缘发绿了,关键它用它内置的拍照app进行拍照,出来的照片没问题的,所以就觉着是不是我哪出问题了,求解个大神!!图片就是这样的
解决方案 »
- android中intent使用疑惑
- android camera开发Method called after release()问题
- Android里面的handler怎么知道将Message对象发送给哪个线程的Looper啊?
- Android初学者的学习笔记(陆续更新)
- 谁能发个gps定位的源码给我。
- 高手请帮忙:关于动态生成编辑框的问题?
- swiffy将flash转换html5后,webview调用html5很慢
- android textview聚焦后边框发光效果
- 安卓编程小菜鸟之RadioButton
- 从html源码中获取URL链接,在线等了
- android百度地图反地理编码不回调
- IndexOutOfBoundsException: setSpan (12 ... 12) ends beyond length 6
public void takePic(final String SavePath, final String SaveFile){
if (camera!= null) {
camera.autoFocus(null);
Camera.Parameters parameters = camera.getParameters();
parameters.setPictureSize(mWidth, mHeight);
parameters.setPictureFormat(PixelFormat.JPEG);// 设置照片的输出格式
parameters.set("jpeg-quality", 80);// 照片质量
camera.setParameters(parameters);
camera.takePicture(null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
String fileName;
if(TextUtils.isEmpty(SaveFile)){
fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".jpg";
}else{
fileName = SaveFile;
}
File out = new File(SavePath, fileName);
try {
FileOutputStream outStream = new FileOutputStream(out);
outStream.write(data);
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
camera.startPreview();
}
}); // 拍照
}
}