【问题标题】:send image onclick to zoom activity发送图像 onclick 以缩放活动
【发布时间】:2017-02-28 14:29:26
【问题描述】:

我正在尝试从我的 main_activity 发送图像以缩放活动。

我有一个 onclick 功能:

   case R.id.imageViewHero:

            String image = ViewHolder.this.post.getImageUrl();

            Intent intentv = new Intent(context, Zoom.class);

            Bundle extras = new Bundle();
            extras.putParcelable("imagebitmap", image);
            intentv.putExtras(extras);
            context.startActivity(intentv);

break;

问题是字符串图像,我不知道下一步该怎么做才能将其发送到缩放。有什么想法吗?

如果需要,我的 zoom.class:

public class Zoom  extends Activity {


@SuppressLint("NewApi")



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_zoom);

    Bundle extras = getIntent().getExtras();
    Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");

    ImageView imgDisplay;
    Button btnClose;


    imgDisplay = (ImageView) findViewById(R.id.imgDisplay);
    btnClose = (Button) findViewById(R.id.btnClose);


    btnClose.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Zoom.this.finish();
        }
    });


    imgDisplay.setImageBitmap(bmp );

}

}

【问题讨论】:

  • 你想在 ImageView 中设置图像还是别的什么?
  • @AsutoshPanda 我想把它设置在@+id/imgDisplay
  • 您是否将图像 url 或图像位图传递给缩放活动?
  • 网址,我想将其转换为位图并发送到缩放,或者将其转换为缩放...我不知道什么会更好...@JerinAMathews

标签: android android-studio android-intent android-imageview


【解决方案1】:

代码大部分是正确的,除了从图像 URL 生成位图的一个错误。

您不能像以前那样从图像 URL 制作位图图像。

它已经在 StackOverflow 上得到了回答。 查看此链接,了解如何将图像从图像 URL 转换为位图 - How to get bitmap from a url in android?

基本上,您从 Intent 获取图像 URL,您从前一个 Activity 传递该图像 URL,在 Zoom Activity 中,将其保存到字符串变量,从中制作位图,将位图设置为 ImageView。

【讨论】:

  • 感谢您的回答!我根据此链接尝试编辑了我的问题。如果可能的话,为了解决我的问题,你能看到 image2 有什么问题吗? (如果我的方法是正确的)
  • 您需要像您正在做的那样将图像 URL 传递给 Zoom 活动。您需要制作 Bitmap 并将其设置在 Zoom Activity 中,而不是在第一个 Activity 中
【解决方案2】:

onClick 方法中,您似乎发送imageUrl。但是在 Zoom.java 中,您将其视为 Bitmap

您可以使用像 Picasso 这样的库来使用图片 URL 填充 ImageView

【讨论】:

    猜你喜欢
    • 2014-03-21
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    • 2023-03-28
    • 2012-08-13
    相关资源
    最近更新 更多