2014-10-04 2 views
0

Может ли кто-нибудь помочь справиться с большим растровым изображением, снятым камерой 8MP. Я столкнулся с ошибкой «Растровое изображение слишком большое, чтобы быть загруженным в текстуру». и что является лучшим способом сжимать изображение по отношению к его пропорциям, чтобы он не терял качество.Обработка большого растрового изображения, сделанного камерой или галереей внутри приложения

Заранее спасибо.

ответ

0

Попробуйте добавить android:largeHeap="true" в проявленном

<application 
    ... 
    android:hardwareAccelerated="false" 
    android:largeHeap="true" > 

ИЛИ Попробуйте этот метод

private Bitmap getBitmap(String path) { 

Uri uri = getImageUri(path); 
InputStream in = null; 
try { 
final int IMAGE_MAX_SIZE = 1200000; // 1.2MP 
in = mContentResolver.openInputStream(uri); 

// Decode image size 
BitmapFactory.Options o = new BitmapFactory.Options(); 
o.inJustDecodeBounds = true; 
BitmapFactory.decodeStream(in, null, o); 
in.close(); 



int scale = 1; 
while ((o.outWidth * o.outHeight) * (1/Math.pow(scale, 2)) > 
     IMAGE_MAX_SIZE) { 
    scale++; 
} 
Log.d(TAG, "scale = " + scale + ", orig-width: " + o.outWidth + ", 
    orig-height: " + o.outHeight); 

Bitmap b = null; 
in = mContentResolver.openInputStream(uri); 
if (scale > 1) { 
    scale--; 
    // scale to max possible inSampleSize that still yields an image 
    // larger than target 
    o = new BitmapFactory.Options(); 
    o.inSampleSize = scale; 
    b = BitmapFactory.decodeStream(in, null, o); 

    // resize to desired dimensions 
    int height = b.getHeight(); 
    int width = b.getWidth(); 
    Log.d(TAG, "1th scale operation dimenions - width: " + width + ", 
     height: " + height); 

    double y = Math.sqrt(IMAGE_MAX_SIZE 
      /(((double) width)/height)); 
    double x = (y/height) * width; 

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(b, (int) x, 
     (int) y, true); 
    b.recycle(); 
    b = scaledBitmap; 

    System.gc(); 
    } else { 
    b = BitmapFactory.decodeStream(in); 
    } 
    in.close(); 

    Log.d(TAG, "bitmap size - width: " +b.getWidth() + ", height: " + 
    b.getHeight()); 
    return b; 
} catch (IOException e) { 
Log.e(TAG, e.getMessage(),e); 
return null; 
} 
+0

Я уже добавил это. не работает для меня – Jatin

1

ширину и высоту изменения относительно рациона изображения динамически и создать новый бит изображения карты

Bitmap bitmap = Bitmap.createScaledBitmap(capturedImage, width, height, true); 
Смежные вопросы