D / skia: --- SkAndroidCodec :: NewFromStream вернул ноль - PullRequest
0 голосов
/ 16 мая 2018

Я пытаюсь изменить размер растрового изображения, и во время рабочего процесса это исключение блокирует меня.

Что с этим не так?

public Bitmap decodeSampledBitmapFromUri(Uri fileUri, int reqWidth, int reqHeight)  {
    InputStream stream = null;
    try {stream = new BufferedInputStream(mApplicationContext.getContentResolver().openInputStream(fileUri)); } catch (FileNotFoundException e) {Log.e("TAG","InputStream stream is null");}
    try { stream.mark(stream.available()); } catch (IOException e) {Log.e("TAG","Thrown IOException in stream.mark(stream.available()");}

    if (stream == null) {Log.e("TAG","stream is null");}
    BitmapFactory.Options options = new BitmapFactory.Options();
    // First decode with inJustDecodeBounds=true to check dimensions
    options.inJustDecodeBounds = true;
    try {stream.reset(); } catch (IOException e) {Log.e("TAG","Thrown IOException in stream.reset() 1");}
    BitmapFactory.decodeStream(stream, null, options);


    try {stream.reset(); } catch (IOException e) {Log.e("TAG","Thrown IOException in stream.reset() 2");}
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;
    try {stream.reset(); } catch (IOException e) {Log.e("TAG","Thrown IOException in stream.reset() 3");}
    BitmapFactory.decodeStream(stream, null, options);
    // Decode bitmap with inSampleSize set
    try {stream.reset(); } catch (IOException e) {Log.e("TAG","Thrown IOException in stream.reset() 4");}
    return BitmapFactory.decodeStream(stream, null, options);
}

05-16 16:31:14.621 com.example.xxx E/TAG: Thrown IOException in stream.reset() 4
05-16 16:31:14.621 com.example.xxx D/skia: --- SkAndroidCodec::NewFromStream returned null

Любой намек на этот вопрос? Я использую Android 8

1 Ответ

0 голосов
/ 16 мая 2018

Для тех, кто сталкивался с тем же, ниже решал это.

    byte[] imageData = null;
    InputStream is = null;
    try { is = new BufferedInputStream(mApplicationContext.getContentResolver().openInputStream(fileUri)); } catch (FileNotFoundException e) {Log.e("TAG","FILEnotFoundException");}
    try { imageData = IOUtils.toByteArray(is); } catch (IOException e) {Log.e("TAG","imagedata IOException");}
    try { is.close(); }  catch (IOException e) {Log.e("TAG","is.close() IOException");}
    // First decode with inJustDecodeBounds=true to check dimensions
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    Bitmap reducedBitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options);
    return  Bitmap.createScaledBitmap(reducedBitmap, reqWidth, reqHeight, false);
...