// 拍照成功回调函数
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进行拍照,出来的照片没问题的,所以就觉着是不是我哪出问题了,求解个大神!! 图片就是这样的
2 个解决方案
#1
你是调用系统的相机,拍出来的颜色问题,个人认为是系统问题,你换个设备看一下
#2
拍照前要先设置相应的参数.这是参考代码
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();
}
}); // 拍照
}
}
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();
}
}); // 拍照
}
}
#1
你是调用系统的相机,拍出来的颜色问题,个人认为是系统问题,你换个设备看一下
#2
拍照前要先设置相应的参数.这是参考代码
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();
}
}); // 拍照
}
}
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();
}
}); // 拍照
}
}