Implement a Take Picture + Crop or use premade Intents?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 14:09:48

问题


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.


回答1:


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.




回答2:


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 :)



来源:https://stackoverflow.com/questions/16397279/implement-a-take-picture-crop-or-use-premade-intents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!