1

我有以下内容:

图片所在位置的很长的 URL(在互联网上)

String imageAddress = data.getExtras().get("imageHTTP").toString();

返回很好,并且有一个以 .jpg 结尾的图像

下一部分是我遇到问题的地方。基本上我有一个接受 Uri 的作物意图,但以下不起作用:

Uri imageUri = Uri.parse(imageAddress);
Intent intent = new Intent(this, com.android.camera.CropImage.class);
intent.setData(uri);
intent.putExtra("return-data", true);
startActivityForResult(intent, CROP);

有任何想法吗?

以下错误代码:

got exception decoding bitmap 
java.lang.NullPointerException
at com.android.camera.Util.makeInputStream(Util.java:337)
4

1 回答 1

0

我想通了。更容易将其保存到 sdcard 临时然后裁剪,然后删除临时的。之后我通过下载的裁剪库运行它(不知道从哪里下载它,但有一些)。

File file = null;

            try {
                URL myImageURL = new URL(imagePath);
                HttpURLConnection connection = (HttpURLConnection)myImageURL.openConnection();
                connection.setDoInput(true);
                connection.connect();
                InputStream input = connection.getInputStream();

                // Get the bitmap
                Bitmap myBitmap = BitmapFactory.decodeStream(input);

                // Save the bitmap to the file
                String path = Environment.getExternalStorageDirectory().toString() + "/polygonattraction/app/";
                OutputStream fOut = null;
                file = new File(path, "temp.png");
                fOut = new FileOutputStream(file);

                myBitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
                fOut.flush();
                fOut.close();
            }
            catch (IOException e) {}

            Log.w("tttt", "got bitmap");

            Uri uri = Uri.fromFile(file);
于 2012-07-15T15:30:32.810 回答