Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Get Bitmap Size Get Free Memory Exception Android

Bitmap size calculation:
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)

Get bitmap size without allocation of memory:

   	BitmapFactory.Options options = new BitmapFactory.Options();
        // If set to true, the decoder will return null (no bitmap), but the out... fields will still
        // be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels. 
    	options.inJustDecodeBounds = true; 
    	BitmapFactory.decodeResource(getResources(), R.drawable.my_image, options);
    	int imageHeight = options.outHeight; // 1024
    	int imageWidth = options.outWidth; // 860
    	String imageType = options.outMimeType; // .jpg .png .gif
 


Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    float density = getResources().getDisplayMetrics().density;

    Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
    Debug.getMemoryInfo(memoryInfo);
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    final int freeMemory = (int) (Runtime.getRuntime().freeMemory() / 1024);
    String memMessage = String.format(
        "Free=%d kB,

MaxMem=%d kB,
Memory: Pss=%.2f MB, Private=%.2f MB, Shared=%.2f MB", freeMemory, maxMemory, memoryInfo.getTotalPss() / 1024.0, memoryInfo.getTotalPrivateDirty() / 1024.0, memoryInfo.getTotalSharedDirty() / 1024.0); ((TextView)findViewById(R.id.textViewInfo)).setText(memMessage );

396LW NO topic_id




AD

Další témata ....(Topics)


166

Multiple substitutions specified in non-positional format | multiple-substitutions-specified-in-non-positional-format


Multiple substitutions specified in non-positional format;did you mean to add the formatted="false" attribute?
Wiktionary, WiktionarySimple
location C:\documents\WiktionarySimple\res\values\strings.xml
Issue:


    <string name="template_user_agent">"%s/%s (Linux; Android)"</string>
    <string name="template_wotd_title">"Wiktionary:Word of the day/%s %s"</string>
    <string name="template_define_url">"//en.wiktionary.org/wiki/%s"</string>

Solution:

   <string name="template_user_agent" translatable="false">"%1$s/%2$s (Linux; Android)"</string>
    <string name="template_wotd_title">"Wiktionary:Word of the day/%1$s %2$s"</string>
    <string name="template_define_url" translatable="false">"//en.wiktionary.org/wiki/%s"</string>

283

WAV Sound Quality is Poor Android MediaPlayer | wav-sound-quality-is-poor-android-mediaplayer


Try convert WAV file to MP3 format for example by Audacity sound editor and replay:
//audacity.sourceforge.net/help/faq_i18n?s=install&i=lame-mp3


MediaPlayer mp  = MediaPlayer.create(getApplicationContext(), R.raw.mymp3file);
mp.setLooping(true);
mp.start();

222

Disable enable internet connection in Android Emulator | disable-enable-internet-connection-in-android-emulator


If you try function for checking internet connection you can disable internet on the emulator:
Settings - Wireless and networks - Mobile networks - Data enabled (checked - unchecked )


 public boolean isNetworkAvailable() {
        ConnectivityManager cm = (ConnectivityManager) 
          getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) {
            return true;
        }
        return false;
    }