如何发送由凌空下载到下一个活动的图像 [英] How to send an image downloaded by volley to the next activity

查看:284
本文介绍了如何发送由凌空下载到下一个活动的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用凌空下载图片和文字列表视图在我活动。
在点击一个i行同时通过图像和文字为详细活动
详细活动我想通过仅图片到另一个活动。

的S / O研究之后我发现了一个code的作品:

\r
\r

BitmapDrawable BD =(BitmapDrawable)((NetworkImageView)view.findViewById(R.id .img2))\r
                    .getDrawable();\r
            位图bitmapzoom = bd.getBitmap();\r
            ByteArrayOutputStream BAOS =新ByteArrayOutputStream();\r
            bd.getBitmap()的COM preSS(Bitmap.Com pressFormat.PNG,100,BAOS)。\r
            字节[] = imgByte baos.toByteArray();\r
            意向意图=新意图(getApplicationContext(),ZoomImage.class);\r
            intent.putExtra(形象,imgByte);\r
            startActivity(意向);\r
        }\r
    });

\r

\r
\r

,并在下次活动我找回它,如:

\r
\r

捆绑额外= getIntent()getExtras();\r
        字节[] B = extras.getByteArray(图像);\r
\r
        BMP位图= BitmapFactory.de codeByteArray的(B,0,b.length个);\r
        BitmapDrawable背景=新BitmapDrawable(BMP);\r
        findViewById(R.id.img2).setBackgroundDrawable(背景);

\r

\r
\r

但图像被放在一个背景图片。我想将图像放在我的 ImageView的。
不会像它是在code上面做的方式的背景。

目前设置在ImageView的形象一直没有successfull.Any建议将受到欢迎。

layout.xml

\r
\r

< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com / APK / RES / Android的\r
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s\r
    机器人:layout_width =match_parent\r
    机器人:layout_height =match_parent\r
    机器人:背景=#000\r
    机器人:方向=垂直\r
    工具:上下文=com.softtech.stevekamau.buyathome.ZoomImage>\r
\r
    < ImageView的\r
        机器人:ID =@ + ID /后退\r
        机器人:layout_width =60dp\r
        机器人:layout_height =60dp\r
        机器人:SRC =@绘制/后退/>\r
\r
    < RelativeLayout的\r
        机器人:ID =@ + ID / root_layout\r
        机器人:layout_width =match_parent\r
        机器人:layout_height =match_parent\r
        机器人:背景=#000>\r
\r
        < ImageView的\r
            机器人:ID =@ + ID / IMG2\r
            机器人:layout_width =300dp\r
            机器人:layout_height =300dp\r
            机器人:layout_centerHorizo​​ntal =真\r
            机器人:layout_centerVertical =真\r
            机器人:scaleType =黑客帝国\r
            安卓了maxHeight =100dp\r
            安卓了maxWidth =50dp/>\r
    < / RelativeLayout的>\r
    < / LinearLayout中>

\r

\r
\r

如何看起来作为背景:


解决方案

编辑:要使用位图设置ImageView的实际图像,而不是bitmapdrawable:

 捆绑额外= getIntent()getExtras()。
字节[] B = extras.getByteArray(图像);BMP位图= BitmapFactory.de codeByteArray的(B,0,b.length个);
findViewById(R.id.img2).setImageBitmap(BMP);

在传递活动之间的大型图像小心,它可能不会在其他活动显示图像。更好地保存到内部或外部存储器中,然后把它的其他活动。

I am using volley to download images and text on a listview in my activity. On clicking a row i pass both the image and the text to Details activity. On details activity i would like to pass only the Image to yet another activity.

After research on S/O i found a code that works:

BitmapDrawable bd = (BitmapDrawable) ((NetworkImageView) view.findViewById(R.id.img2))
                    .getDrawable();
            Bitmap bitmapzoom=bd.getBitmap();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bd.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, baos);
            byte[] imgByte = baos.toByteArray();
            Intent intent=new Intent(getApplicationContext(),ZoomImage.class);
            intent.putExtra("image", imgByte);
            startActivity(intent);
        }
    });

And on the next activity i retrieve it like:

Bundle extras = getIntent().getExtras();
        byte[] b = extras.getByteArray("image");

        Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
        BitmapDrawable background = new BitmapDrawable(bmp);
        findViewById(R.id.img2).setBackgroundDrawable(background);

However the image is being placed as a background image.I would like to place the image in my ImageView. Not as a background like the way it is done on the code above.

Currently setting the image on the ImageView has not been successfull.Any suggestions will be welcomed.

layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000"
    android:orientation="vertical"
    tools:context="com.softtech.stevekamau.buyathome.ZoomImage">

    <ImageView
        android:id="@+id/back"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:src="@drawable/back"/>

    <RelativeLayout
        android:id="@+id/root_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000">

        <ImageView
            android:id="@+id/img2"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:scaleType="matrix"
            android:maxHeight="100dp"
            android:maxWidth="50dp" />
    </RelativeLayout>
    </LinearLayout>

How it looks as a background:

解决方案

EDIT: To set the imageview actual image using a bitmap, not the bitmapdrawable:

Bundle extras = getIntent().getExtras();
byte[] b = extras.getByteArray("image");

Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
findViewById(R.id.img2).setImageBitmap(bmp);

Careful in passing large images between activities, it might not show the image in the other activity. Better to save to internal or external memory and then get it on the other activity.

这篇关于如何发送由凌空下载到下一个活动的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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