Java的机器人,从画廊得到的图像,并显示在屏幕上(错误) [英] Java android, getting image from gallery and show it on screen (error)

查看:101
本文介绍了Java的机器人,从画廊得到的图像,并显示在屏幕上(错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次发布问题,所以在这里它去。结果
我要推一个按钮,所以它打开画廊,选择一个图片,然后显示它的地方在屏幕上(布局)上。

First time I post a question, so here it goes.
I want to push on a button, so it opens the gallery, pick a picture, then shows it somewhere on the screen (layout).

我走到这一步现在:

public void FotoKiezen(View v) {
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, 1);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case 1:
     {
      if (resultCode == RESULT_OK)
      {
        Uri photoUri = data.getData();
        if (photoUri != null)
        {
        try {
              String[] filePathColumn = {MediaStore.Images.Media.DATA};
              Cursor cursor = getContentResolver().query(photoUri, filePathColumn, null, null, null); 
         cursor.moveToFirst();
     int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
     String filePath = cursor.getString(columnIndex);
     cursor.close();
     Bitmap bMap = BitmapFactory.decodeFile(filePath);
     ImageView.setImageBitmap(bMap);


     }catch(Exception e)
      {}
      }
    }// resultCode
    }// case 1
    }// switch, request code
}// public void onActivityResult

有一些其他的code上面过,但这里的某个地方有问题。

There is some other code above it too, but here somewhere is the problem.

我上线的误差 ImageView.setImageBitmap(BMAP);
错误:

I get an error on the line ImageView.setImageBitmap(bMap); The error:

无法进行静态引用从类型ImageView的非静态方法setImageBitmap(位图)

Cannot make a static reference to the non-static method setImageBitmap(Bitmap) from the type ImageView

我在互联网上搜索了很多,尝试了很多东西,但我不解决这个问题。
也许这是很容易的,我只是没有看到它。

I searched a lot on the internet, and tried many things, but I can't resolve it. Maybe it is really easy and I just don't see it.

我在的Java编程的机器人,用于在C ++编程初学者。
所以也有关错误的一些解释将是非常好的:D

I am beginner at Java android programming, used to program in C++. So also some explanation about the error would be very nice :D

推荐答案

您必须创建的ImageView类的对象?例如:

You must create the object of ImageView class? For example:

ImageView img = new ImageView(this);
img.setImageBitmap(bMap);

ImageView img = (ImageView)findViewById(R.id.<your image view id>);
img.setImageBitmap(bMap);

这篇关于Java的机器人,从画廊得到的图像,并显示在屏幕上(错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆