Implement a Take Picture + Crop or use premade Int

2019-04-15 20:58发布

I'm in the middle of an Android app which takes a picture, crops it and does some extra stuff. I was hoping to do my own cropping system, but the problem comes when I test in different places. Pictures appear rotated in some cases, and not correctly cropped in others (like they had an extra margin around (seeing extra space of the original picture), or so).

More on that, I've considered using Intents. This would release me from the picture taking madness, the cropping, and would add an interesting "get from gallery" option, which I haven't implemented yet. Crop intent may not be in every Android (as it comes with the vanilla Camera app, and some devices just don't have it), so external libraries should be on my way, too.

However, the way I was using crop and picture taking was "automatic", meaning a single button took a square picture (out of a square view of the camera), being cropped at the same time (and with some post processing too), without issuing the user, and the crop libraries I've seen don't work that way (they open a new Activity).

Now comes the question: Would it be better to leave the work to Intents (and/or external libraries) and rethink the logic of the app, or to stick to the current code and do edge-case modifications as they appear (rotate in some devices and not in others, crop differently, etc)?

PD: I know this question might not be as development-tight as others (some will say: no lines of code > no SO!), but it is indeed something related to coding as well, so I find no better place to ask it.

2条回答
甜甜的少女心
2楼-- · 2019-04-15 21:43

Facebook and Instagram have succesfully done it with their own libraries or third party code. Having already started work on your own cropping library i suggest you take it all the way, borderline cases, optimisations and workarounds will be there, no doubt but you will be in control. for example, The orientation problem that you talked about can be handled like this :

orientationColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.ORIENTATION);     

cursor.getInt(orientationColumnIndex)
if(orient == 90 || orient == 180 || orient == 270 ){
  Matrix matrix = new Matrix();
  matrix.postRotate(orient);
  result = Bitmap.createBitmap(result, 0, 0, 4*screenWidth/15, 4*screenWidth/15, matrix, true);
}

Using the default android intent for cropping, as you suggested, isnt very reliable for an app made for wide potential user base.

查看更多
来,给爷笑一个
3楼-- · 2019-04-15 22:01

Just a note on open source / 3rd party crop libraries - you should look over the source and make sure they are not using a crop intent (e.g., com.android.camera.action.CROP) as CommonsWare points out here and in his helpful blog post: http://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html

I have been evaluating different crop libraries/open source on github and some of them are using a crop intent.

This, of course, assumes you care that cropping should work on all Android devices :)

查看更多
登录 后发表回答