在ImageView的交换图片 [英] Swapping Image in ImageView

查看:203
本文介绍了在ImageView的交换图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想实现我的应用程序的简单(我认为)的事情。我认为这将是简单的,但不知何故,这是行不通的,因为我想它想。

我试图做的是:


  • 有一个在中心ImageView的活动 - 它有它自己的形象(当然,还有两个)

  • 我要preSS的ImageView的(也可能是ImageButton的),打开画廊/拍照与摄像头。

  • 然后,取/捡照片后,我要特别强调的ImageView显示图片的缩略图。

我的布局
                   

 < ImageView的
                    机器人:ID =@ + ID / add_photo_left
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_marginRight =20dp
                    机器人:layout_weight =1
                    机器人:adjustViewBounds =真
                    机器人:SRC =@绘制/ add_photo_button/>                < ImageView的
                    机器人:ID =@ + ID / add_photo_right
                    机器人:layout_width =0dp
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_weight =1
                    机器人:adjustViewBounds =真
                    机器人:SRC =@绘制/ add_photo_button/>
            < / LinearLayout中>

我的code - 让图片的路径之后

  BitmapFactory.Options bmpFactoryOptions =新BitmapFactory.Options();
        bmpFactoryOptions.inSampleSize = 8;
        位图位图= BitmapFactory.de codeFILE(/ SD卡/ 5.png,bmpFactoryOptions);
        lastClicked.setImageBitmap(位图);
        //lastClicked.setImageResource(R.drawable.green_circle);

我想要做的是读取文件大小(用inSampleSize)从SD卡,然后用它填充的ImageView(或ImageButton的)。
但是,使用setImageBitmap功能后,该视图中消失 - 就像刚装入空的图像(注释行正常工作 - 它只是绿点)。

也许有人已经接近类似的问题?我更AP preciate任何形式的帮助。

格尔茨,
SCANA

编辑:
OFC lastClicked:

  lastClicked =(ImageView的)findViewById(R.id.add_photo_left);


解决方案

为什么不试试 lastClicked.invalidate()

我在code。至少这样做,是这样工作的;)

I've been trying to implement simple (I think) thing in my app. I thought it would be simple, but somehow it doesn't work as I would wanted it to.

What I'm trying to do is:

  • There is an activity with ImageView in center - it has it's own image (well, there's two of them).
  • I want to press that ImageView (or it could be ImageButton), open the gallery/take picture with camera.
  • Then, after taking/picking a picture, I want to make that ImageView display the thumbnail of picture.

My layout

                <ImageView
                    android:id="@+id/add_photo_left"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="20dp"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@drawable/add_photo_button" />

                <ImageView
                    android:id="@+id/add_photo_right"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@drawable/add_photo_button" />
            </LinearLayout>

My code - after getting picture path

        BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
        bmpFactoryOptions.inSampleSize = 8;
        Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/5.png",bmpFactoryOptions);
        lastClicked.setImageBitmap(bitmap);
        //lastClicked.setImageResource(R.drawable.green_circle);

What I wanted to do is to read the resized file (using inSampleSize) from sdcard, and then fill ImageView (or ImageButton) with it. But after using setImageBitmap function, the view disappears - like it just loaded empty image (commented line works properly - it's just green dot).

Maybe someone has approached similar problem? I would much appreciate any kind of help.

Greetz, scana

EDIT: ofc lastClicked:

lastClicked = (ImageView)findViewById(R.id.add_photo_left);

解决方案

Why don't you try lastClicked.invalidate() ?

I do so in my code at least and it works this way ;)

这篇关于在ImageView的交换图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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