实际上从我的相机中获取位图有一些问题 我的代码:
private Bitmap loadBitmap(Uri imageUri) {
float dw = 720;
float dh = 600;
Bitmap returnBmp = Bitmap.createBitmap((int) dw, (int) dh, Bitmap.Config.ARGB_4444);
try {
BitmapFactory.Options bmpFactorOptions = new BitmapFactory.Options();
bmpFactorOptions.inJustDecodeBounds = true;
returnBmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri), null, bmpFactorOptions);
int heightRatio = (int) Math.ceil(bmpFactorOptions.outHeight / dh);
int widthRatio = (int) Math.ceil(bmpFactorOptions.outWidth / dw);
if (heightRatio > widthRatio) {
bmpFactorOptions.inSampleSize = heightRatio;
} else {
bmpFactorOptions.inSampleSize = widthRatio;
}
bmpFactorOptions.inJustDecodeBounds = false;
returnBmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri), null, bmpFactorOptions);
} catch (FileNotFoundException e) {
Log.v("ERROR", e.toString());
}
return returnBmp;
}
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
Camera.Parameters parameters = camera.getParameters();
List<String> colorEffects = parameters.getSupportedColorEffects();
camera.setParameters(parameters);
try {
camera.setPreviewDisplay(holder);
} catch (IOException exception) {
camera.release();
}
camera.startPreview();
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera.release();
}
public void BitMap(View v) {
camera.takePicture(null, null, null, GetPhoto.this);
}
public void onPictureTaken(byte[] data, Camera camera) {
Uri snap = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new ContentValues());
bmp3 = loadBitmap(Uri.parse(snap.getPath()));
canvas = new Canvas(bmp3);
paint = new Paint();
canvas.drawBitmap(bmp3, 0, 0, paint);
test.setImageBitmap(bmp3);
photobit=bmp3;
Toast t = Toast.makeText(this, bmp3.toString(), Toast.LENGTH_LONG);
t.show();
try {
OutputStream imageFile = getContentResolver().openOutputStream(snap);
imageFile.write(data);
imageFile.flush();
imageFile.close();
} catch (FileNotFoundException e) {
Toast td = Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG);
td.show();
} catch (IOException e) {
Toast td = Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG);
td.show();
}
camera.startPreview();
}
当我调用我的位图方法时
public void BitMap(View v) {
camera.takePicture(null, null, null, GetPhoto.this);
}
我在输出上获得透明位图 哪里可以成为我的问题? 我的类实现了SurfaceHolder.Callback,Camera.PictureCallback