【问题标题】:passing high resolution images from one activity to other将高分辨率图像从一项活动传递到另一项活动
【发布时间】:2017-02-28 12:36:56
【问题描述】:

我正在 Android Studio 中创建一个图像过滤器应用。首先,用户从图库中选择一个图像,它将显示在 imageview 中。然后用户单击编辑按钮,该图像显示在下一个活动的图像视图中,我们可以在其中添加过滤器......它适用于低分辨率图像但是当我选择任何高分辨率图像时它显示在第一个图像视图中但是当我单击编辑时按钮应用程序崩溃或显示我选择的最后一张图片。我搜索了解决方案,但找不到。如果有人知道如何解决这个问题,请帮助我

【问题讨论】:

    标签: android


    【解决方案1】:

    可以通过 Intent 传递的数据大小是有限制的。限制为roughly 500Kb - 您的高分辨率照片会比这更大。

    考虑将图像保存到设备上的某个文件位置,将 URI 传递给接收活动并在其中加载它。

    【讨论】:

      【解决方案2】:

      首先粘贴崩溃日志。 然后不是传递图像本身,而是传递图像路径。 或者只是在一个活动中添加编辑工具和 mainView 并使编辑工具不可见!但是你也可以使用片段。

      【讨论】:

        【解决方案3】:

        与 putExtra 一起使用以发送 Uri 路径:

         Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent .setClass(ThisActivity.this,  NewActivity.class);
                    intent .putExtra("KEY", Uri);
                    startActivity(intent );
        

        你只需要添加图片的路径。

        【讨论】:

          【解决方案4】:

          最好将图片保存在storage中,传递location的Uri,而不是传递图片。

          将图像保存到存储中:-

          public static Uri saveImageOnExternalStorage(Bitmap capturedBitmap, String imageId) {
              if (null != capturedBitmap ) {
          
                  OutputStream fOutputStream;
          
                  String path = Environment.getExternalStorageDirectory().toString();
              File file = new File(path + "temp", mediaId + ".png");
                  file.delete();
                  if (!file.getParentFile().exists()) {
                      file.getParentFile().mkdirs();
                  }
                  try {
                      if (file.createNewFile()) {
                          fOutputStream = new FileOutputStream(file);
          
                          capturedBitmap.compress(COMPRESS_FORMAT, 100, fOutputStream);
          
                          fOutputStream.flush();
                          fOutputStream.close();
          
                          return Uri.fromFile(file); // return saved image path on external storage
                      }
                  } catch (FileNotFoundException e) {
                      Log.e(TAG,e.getMessage());
                      return null;
                  } catch (IOException e) {
                      e.printStackTrace();
                      Log.e(TAG,e.getMessage());
                  }
              }
              return null;
          } 
          

          现在您可以在下一个活动的意图中传递相同的 Uri:-

          Intent intent = new Intent(CurrentActivity.this,  LaunchActivity.class);
                      intent .putExtra("image_key", Uri);
                      startActivity(intent );
          

          【讨论】:

            猜你喜欢
            • 2012-01-24
            • 1970-01-01
            • 2014-09-19
            • 1970-01-01
            • 2014-09-17
            • 1970-01-01
            • 2012-03-05
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多