我使用相机API拍照我必须根据我的图像视图大小打开不同大小的相机。我正在按照我们在名为“ApiDemo”的Android sdk/sample/adroid-18中获得的示例项目进行操作,但我已更改的内容未在setcontentview上设置相机。我已经在Frame Layout上设置了相机。起初我的相机预览被弄糊了,所以我得到了相机OptimalPreviewSize,并将FrameLayout参数的宽度和高度设置为wrap-content.Now相机预览比ImageView小(我想要的大小)。如果我将FrameLayout参数的大小设置为match-parent,那么相机View就是stretch.How来解决这个问题。中心裁剪图像在适当的大小设置ImageView
找到此链接更多规格。 Android camera preview look strange
UPDATE
我的相机预览大小是好的,现在我使用的布局方法的想法是我有更大的布局,然后我的ImageView,现在相机预览看起来很不错。 现在我面临的问题是设置合适的大小的图像,我必须将裁切和缩放中心放在同一大小中,就像我的ImageView.This图片我通过TakePicture方法获取并保存在SD卡中。
为了这个,我用这个方法: -
public Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
// Compute the scaling factors to fit the new height and width, respectively.
// To cover the final image, the final scaling will be the bigger
// of these two.
float xScale = (float) newWidth/sourceWidth;
float yScale = (float) newHeight/sourceHeight;
float scale = Math.max(xScale, yScale);
// Now get the size of the source bitmap when scaled
float scaledWidth = scale * sourceWidth;
float scaledHeight = scale * sourceHeight;
// Let's find out the upper left coordinates if the scaled bitmap
// should be centered in the new size give by the parameters
float left = (newWidth - scaledWidth)/2;
float top = (newHeight - scaledHeight)/2;
// The target rectangle for the new, scaled version of the source bitmap will now
// be
RectF targetRect = new RectF(left+50, top, left + scaledWidth, top + scaledHeight+50);
// RectF targetRect = new RectF(0, 0, newWidth, newHeight/2);
// Finally, we create a new bitmap of the specified size and draw our new,
// scaled bitmap onto it.
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
Canvas canvas = new Canvas(dest);
canvas.drawBitmap(source, null, targetRect, null);
return dest;
}
但结果图像质量不good.Height角从顶部和底部,结果图像质量切割不good.Pixels被拉伸。
不要告诉我使用scaleType = Center_crop我不能在我的情况下使用它,并且不希望向用户显示裁剪帧,这个全部过程不应该显示在UI上。
UPDATE
我从中心和规模,根据我的ImageView大小
Bitmap dstBmp = ThumbnailUtils.extractThumbnail(source, newWidth, newHeight);
,但我得到的位图不看同在的FrameLayout显示相机预览用于农作物图像的打击方法。因为相机预览很大。我认为这些代码裁剪了大面积。 我试图减少宽度和改变高度,但没有得到我想要的比例相同的裁剪图像。
一个更多的想法,我有后图片裁剪自动FrameLayout上设置的最后一帧图像。我们可以从框架布局中获得该设置的框架吗?这怎么可能?
这里是像这样的问题How to retrieve the visible part of a SurfaceView in Android做任何一个有解决办法。
我想通过这条线ThumbnailUtils.extractThumbnail(source, newWidth, newHeight);
来实现这一点,并通过这条线我得到像图中描述的图像的src。
什么改变这一行恰好?
发布您看到的图像的快照 – Prem
完成!请检查更新后的帖子 –
令人难以置信的简单解决方案:http://stackoverflow.com/a/17733530/294884 – Fattie