1

I followed another StackOverflow tutorial where you can capture a bitmap from the camera and set it to your image view. The issue I am having is that the picture that is returned is very small and does not fill the rest of the screen. In my XML I do the following...

<ImageView 
     android:id="@+id/imgview" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

If I change to "fill_parent" I get a larger image, but my question now is how would I go about getting the actual size image and putting it on a scrollable (in both the x and y directions) view container.

Thanks!

BTW, here is the code for capturing the Bitmap from the camera...

public class MainActivity extends Activity implements OnClickListener
{
private ImageView imageView;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.d("matt","1");

    Button b = (Button)this.findViewById(R.id.btn);
    imageView = (ImageView)this.findViewById(R.id.imgview);

    b.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
public void onClick(View v)
{
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent,1888);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if(requestCode == 1888)
    {
        Log.d("matt", "3.a");
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        Log.d("matt", "3.b");
        imageView.setImageBitmap(photo);
        Log.d("matt", "3.c");
    }
}
4

2 回答 2

1

调用者可能会传递一个额外的 EXTRA_OUTPUT 来控制该图像将被写入的位置。如果 EXTRA_OUTPUT 不存在,则在额外字段中将小尺寸图像作为位图对象返回。这对于只需要小图像的应用程序很有用。如果存在 EXTRA_OUTPUT,则将全尺寸图像写入 EXTRA_OUTPUT 的 Uri 值。

于 2013-04-23T09:51:54.040 回答
1

如果您需要捕获图像的尺寸,则可以使用:

int height = photo.getHeight();
int width = photo.getWidth();

否则,如果您想了解捕获的图像大小(以兆字节为单位),请参阅我对这个问题的回答:https ://stackoverflow.com/a/11846455/1512836

[编辑] - 请检查这个以滚动图像视图:Android ScrollView 中的图像

于 2012-08-16T20:53:23.763 回答