0

だから私は次のコードをAsyncTask. はAsyncTask、画像ファイルへの URL を取り込み、それをビットマップにダウンロードし、ビットマップをディスクのどこかに保存してから、ビットマップを既存の に表示しますImageView

doInBackground()私の AsyncTaskの呼び出しの実装は次のとおりです。

    protected Bitmap doInBackground(String... urls) {
        try {
            URL image_url = new URL(urls[0]);
            String image_url_prefix_regex = "http://www\\.somewebsite\\.com";
            if (externalStorageIsAvailable()) {
                String file_path = getExternalFilesDir(null).getPath() + image_url.toString().replaceAll(image_url_prefix_regex, "");
                File target_file = new File(file_path);
                if (!target_file.getParentFile().exists()) {
                    target_file.getParentFile().mkdirs();
                }

                BitmapFactory.Options bitmap_options = new BitmapFactory.Options();
                bitmap_options.inScaled = false;
                bitmap_options.inDither = false;
                bitmap_options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                bitmap_options.inPreferQualityOverSpeed = true;
                bitmap_options.inSampleSize = 1;

                Bitmap image = BitmapFactory.decodeStream(image_url.openStream(), null, bitmap_options);
                image.compress(CompressFormat.JPEG, 100, new FileOutputStream(target_file));
                return image;
            }
        }
        catch (MalformedURLException e) {
            Log.v(DEBUG_TAG, "Error: Caught MalformedURLException");
        }
        catch (IOException e) {
            Log.v(DEBUG_TAG, "Error: Caught IOException");
        }
        return null;
    }

その後、onPostExecute()電話の後半で私はこれを持っています:

    protected void onPostExecute(Bitmap image) {
        ImageView mImageView = (ImageView) findViewById(R.id.main_image);
        mImageView.setImageBitmap(image);
    }

しかし、コードが画像をダウンロードして表示すると、画像のサイズと品質が低下します。結果の画像が完全な品質になるようにするにはどうすればよいですか? これらBitmapFactoryの .Options 設定は、これまでに試したものですが、機能していないようです。

外部ストレージに保存される画像について質問しているわけではないことに注意してください。再び圧縮されるため、品質が低下する可能性が高いと思いますがImageView、それは、私が求めている に送信している画像に影響を与えるべきではありません。もちろん、これらの仮定に問題がある場合は、指摘してください。

4

1 に答える 1

-1

bitmap Stream のデコード中に Bitmap ファクトリ オプションを使用するのはなぜですか? を使用するだけです

 Bitmap image = BitmapFactory.decodeStream(image_url.openStream());

それ以外の

Bitmap image = BitmapFactory.decodeStream(image_url.openStream(), null, bitmap_options);
于 2013-02-15T08:59:01.153 に答える