我正在尝试存储图像并在保存后裁剪它,但我有一个最大的问题,那个问题是当我存储图像时所有的东西都很好但是当我发送URI结果时,crop类打开但是它是空的没有图片 我认为它是空的,因为图像没有成功保存,因此它变为空,所以我认为解决方案是等到图像保存然后打开裁剪类,这是我的代码如下:
Capture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
mCamera.setCameraListener(new CameraListener() {
@Override
public void onPictureTaken(byte[] picture) {
Bitmap result = BitmapFactory.decodeByteArray(picture, 0, picture.length);
final Bitmap resizedbitmap = Bitmap.createScaledBitmap(result, 1200, 1200,false);
new Thread(new Runnable(){@Override public void run() {storeImage(resizedbitmap);}}).start();
if (getOutputMediaFile()!=null){
final Uri mUri = Uri.fromFile(new File(getOutputMediaFile().getPath()));
Intent var6 = new Intent();
var6.putExtra(MediaStore.EXTRA_OUTPUT,mUri);
setResult(RESULT_OK,var6);
finish();
}
}
});
mCamera.captureImage();}});
private void storeImage(Bitmap image) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {runOnUiThread(new Runnable() {
@Override
public void run() {Toast.makeText(camera_fragment.this,R.string.error,Toast.LENGTH_SHORT).show();}});return;}
try {if (getOutputMediaFile()!=null && getOutputMediaFile().exists()){
FileOutputStream fos = new FileOutputStream(pictureFile.toString());
image.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();}}
catch (IOException e) {
runOnUiThread(new Runnable() {@Override public void run() {Toast.makeText(camera_fragment.this,R.string.error,Toast.LENGTH_SHORT).show();}});}
}
private File getOutputMediaFile(){
File mediaStorageDir = new File(Environment.getExternalStorageDirectory() + "/Pictures/Test/");
if (!mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
runOnUiThread(new Runnable() {
@Override
public void run() {Toast.makeText(camera_fragment.this,R.string.error,Toast.LENGTH_SHORT).show();}
});
return null;}}
String timeStamp = new SimpleDateFormat("ddMMyyyyHHmmss",Locale.US).format(new Date());
File mediaFile;
String mImageName=timeStamp +".png";
mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(mediaFile)));
return mediaFile;
}
我也使用Handler等待3秒钟我使用了TimerTask和所有方法,但直到现在我都没有用。
所以请兄弟们解决这个问题。
注意:我正在使用 CAMERAKIT LIBRARAY& UCROP LIBRRARY 。
我在logcat中看不到任何东西,这就是我所拥有的:
08-13 11:57:00.224 21808-21848/com.pcsoftgroup.beta1 V/FA: Recording user engagement, ms: 3756
08-13 11:57:00.227 21808-21848/com.pcsoftgroup.beta1 V/FA: Activity paused, time: 522689769
08-13 11:57:00.230 21808-21848/com.pcsoftgroup.beta1 D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=3756, _sc=camera_fragment, _si=8399813092086441151}]
08-13 11:57:00.282 21808-21848/com.pcsoftgroup.beta1 V/FA: Activity resumed, time: 522689814
08-13 11:57:00.301 21808-21852/com.pcsoftgroup.beta1 W/OpenGLRenderer: Fail to change FontRenderer cache size, it already initialized
08-13 11:57:00.304 21808-21848/com.pcsoftgroup.beta1 V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 36
08-13 11:57:00.308 21808-21848/com.pcsoftgroup.beta1 V/FA: Activity paused, time: 522689849
08-13 11:57:00.374 21808-21808/com.pcsoftgroup.beta1 V/FA: onActivityCreated
08-13 11:57:00.420 21808-21808/com.pcsoftgroup.beta1 D/BitmapLoadUtils: maxBitmapSize: 2078
08-13 11:57:00.424 21808-21848/com.pcsoftgroup.beta1 V/FA: Activity resumed, time: 522689969
08-13 11:57:00.425 21808-21852/com.pcsoftgroup.beta1 W/OpenGLRenderer: Fail to change FontRenderer cache size, it already initialized
08-13 11:57:00.444 21808-22211/com.pcsoftgroup.beta1 D/BitmapWorkerTask: Uri scheme: file
08-13 11:57:00.460 21808-22211/com.pcsoftgroup.beta1 D/skia: --- decoder->decode returned false