2011-06-21 1 views
0

地図のピンサイズに問題があります。ダイナミックネスを維持するために、さまざまなカテゴリのマップピンはサイトのサーバーに格納されているため、アプリケーションの公開後もいつでも変更できます。Android - マップマーカーの表示が異なる(dip/pxまたは減圧)

私はそれらのファイルをダウンロードするたびにキャッシュしています。最後にダウンロードした後に変更されたことを示すメッセージがサーバーから返された場合にのみ、それらを再ダウンロードします。初めてピンをつかむときは、ビットマップをファイルに保存する前にビットマップを使用して、マップマーカーが正しいサイズになっています。その後、イメージファイルからピンの保存されたバージョンを直接ロードしています。これらは、最初にダウンロードしたビットマップを使用した場合よりもかなり小さく表示されます()。

まず、私はPNGを保存する方法に問題があると思ったが、サイズは正しい(64 x 64)。これはdip/pxの問題ですか、何らかのオプションでイメージファイルを解凍する必要がありますか?

public static Bitmap loadMapPin(String category, int width, int height) { 
     URL imageUrl; 
     category = category.toLowerCase().replace(" ", ""); 
     try { 
      imageUrl = new URL(PIN_URL+category+".png"); 
      InputStream is = (InputStream) imageUrl.getContent(); 
      Options options = new Options(); 

      options.inJustDecodeBounds = true; //Only find the dimensions 

      //Decode without downloading to find dimensions 
      BitmapFactory.decodeStream(is, null, options); 

      boolean scaleByHeight = Math.abs(options.outHeight - height) >= Math.abs(options.outWidth - width); 
      if(options.outHeight * options.outWidth >= width * height){ 
       // Load, scaling to smallest power of 2 that'll get it <= desired dimensions 
       double sampleSize = scaleByHeight 
        ? options.outHeight/height 
        : options.outWidth/width; 
       options.inSampleSize = 
        (int)Math.pow(2d, Math.floor(
        Math.log(sampleSize)/Math.log(2d))); 
      } 
      options.inJustDecodeBounds = false; //Download image this time 

      is.close(); 
      is = (InputStream) imageUrl.getContent(); 
      Bitmap img = BitmapFactory.decodeStream(is, null, options); 
      return img; 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 

そして、ここで私は、キャッシュされたファイルからそれらをロードしています方法は次のとおりです:

は、ここで私は、画像を最初につかむ方法です

BitmapFactory.decodeFile(filepath); 

感謝を事前に!

答えて

0

私は、デフォルトでは、画像をビットマップに解凍することは、高密度スクリーンではスケールされないことを発見しました。密度をnoneに設定する必要があります。言い換えれば、画像が未知の濃度であることを指定します。

ソリューション:

Bitmap b = BitmapFactory.decodeFile(filepath); 
b.setDensity(Bitmap.DENSITY_NONE); 
関連する問題