在此处的答案的帮助下,我设法通过为它们创建图像视图来将使用平板电脑拍摄的照片添加到线性布局中。浏览器加载了许多相同布局的副本,就像布局是自定义控件一样。每个布局都有一个按钮来拍摄照片并将其(或应该)添加到自己的线性布局中。
但....
拍完照片后,它会被放入线性视图,但它不在正确的页面中。
使用此代码,它被放置在线性布局中:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap mBitmap;
String _path = Environment.getExternalStorageDirectory().toString() + File.separator + "photo_" + String.valueOf(requestCode) + ".png";
mBitmap = BitmapFactory.decodeFile(_path);
if (mBitmap == null) {
// bitmap still null
} else {
byte[] imageData = null;
try {
final int THUMBNAIL_SIZE = 64;
Float width = new Float(mBitmap.getWidth());
Float height = new Float(mBitmap.getHeight());
Float ratio = width / height;
mBitmap = Bitmap.createScaledBitmap(mBitmap, (int) (THUMBNAIL_SIZE * ratio), THUMBNAIL_SIZE, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
} catch (Exception ex) {
}
ImageView iv = new ImageView(this);
LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
iv.setLayoutParams(params);
iv.setImageBitmap(mBitmap);
iv.setTag(_path);
LinearLayout lvp = (LinearLayout) findViewById(R.id.lvPhotos);
lvp.addView(iv);
}
}
显然我不应该将它用于创建的图像视图,但是如何获取单击相机按钮的页面的上下文?
rg,埃里克