SORU
23 Mart 2010, Salı


BitmapFactory.decodeStream seçenekleri ayarladığınızda boş dönen

BitmapFactory.decodeStream(inputStream) ile ilgili sorunlar yaşıyorum. Seçenekleri olmadan kullanıldığında, görüntü dönecektir. Ama seçenekleri ile birlikte kullandığımda .decodeStream(inputStream, null, options) gibi hiç bit eşlem verir.

Yapmaya çalıştığım şey, aslında hafızayı kaydetmek için yüklemek için önce bir Bitmap altörnekleyebilirsiniz. Bazı iyi kılavuzları, ama hiçbiri .decodeStream kullanarak okudum.

İŞLERİ İYİ GİDİYOR

URL url = new URL(sUrl);
HttpURLConnection connection  = (HttpURLConnection) url.openConnection();

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is, null, options);

İŞE YARAMIYOR

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is, null, options);

InputStream is = connection.getInputStream();

Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

BitmapFactory.decodeStream(is, null, options);

Boolean scaleByHeight = Math.abs(options.outHeight - TARGET_HEIGHT) >= Math.abs(options.outWidth - TARGET_WIDTH);

if (options.outHeight * options.outWidth * 2 >= 200*100*2){
    // Load, scaling to smallest power of 2 that'll get it <= desired dimensions
    double sampleSize = scaleByHeight
    ? options.outHeight / TARGET_HEIGHT
    : options.outWidth / TARGET_WIDTH;
    options.inSampleSize =
        (int)Math.pow(2d, Math.floor(
        Math.log(sampleSize)/Math.log(2d)));
}

// Do the actual decoding
options.inJustDecodeBounds = false;
Bitmap img = BitmapFactory.decodeStream(is, null, options);

CEVAP
27 Mart 2010, CUMARTESİ


Sorun bir HttpUrlConnection bir İnputStream görüntü meta veri getirmek için kullanılan bir kez, ve aynı İnputStream tekrar geri kullanabilirsiniz.

Bu nedenle resmin gerçek örnekleme için yeni bir İnputStream oluşturmak zorunda.

  Options options = new BitmapFactory.Options();
  options.inJustDecodeBounds = true;

  BitmapFactory.decodeStream(is, null, options);

  Boolean scaleByHeight = Math.abs(options.outHeight - TARGET_HEIGHT) >= Math.abs(options.outWidth - TARGET_WIDTH);

  if(options.outHeight * options.outWidth * 2 >= 200*200*2){
         // Load, scaling to smallest power of 2 that'll get it <= desired dimensions
        double sampleSize = scaleByHeight
              ? options.outHeight / TARGET_HEIGHT
              : options.outWidth / TARGET_WIDTH;
        options.inSampleSize = 
              (int)Math.pow(2d, Math.floor(
              Math.log(sampleSize)/Math.log(2d)));
     }

        // Do the actual decoding
        options.inJustDecodeBounds = false;

        is.close();
        is = getHTTPConnectionInputStream(sUrl);
        Bitmap img = BitmapFactory.decodeStream(is, null, options);
        is.close();

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BASS212M

    BASS212M

    15 Temmuz 2009
  • DJPixcell

    DJPixcell

    20 NİSAN 2007
  • joshsnice

    joshsnice

    28 Kasım 2006