1

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.

4

2 回答 2

1

Facebook 和 Instagram 已经通过他们自己的库或第三方代码成功地做到了这一点。已经开始在您自己的裁剪库上工作,我建议您一直使用它,边界案例、优化和变通方法将在那里,毫无疑问,但您将掌控一切。比如你说的方向问题可以这样处理:

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);
}

正如您所建议的那样,使用默认的 android 意图进行裁剪对于为广泛的潜在用户群制作的应用程序来说不是很可靠。

于 2013-05-06T11:17:20.620 回答
0

只是关于开源/第 3 方裁剪库的注释 - 您应该查看源代码并确保它们没有使用裁剪意图(例如,com.android.camera.action.CROP),正如 CommonsWare 在这里和他的帮助中指出的那样博客文章:http ://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html

我一直在 github 上评估不同的作物库/开源,其中一些正在使用作物意图。

当然,这假设您关心裁剪应该适用于所有 Android 设备:)

于 2013-09-10T18:14:06.203 回答