0

the image size is 4 Mb, it's a jpg. I haven't any problem if i try to change the background with another sample image (with a smaller size , for example the ic_launcher sample).

Should be a problem with a size? 2667 × 4733 it's the image dimension.

I use a samsung s4 mini for debug, it may be useful.

this is the code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="1"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/mioartista"    
    tools:context="com.example.settingavatar.MyAvatar" >

    <!-- other things -->

</RelativeLayout>

this is the error log

10-15 10:08:43.461: E/AndroidRuntime(3438): FATAL EXCEPTION: main
10-15 10:08:43.461: E/AndroidRuntime(3438): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.settingavatar/com.example.settingavatar.MyAvatar}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
10-15 10:08:43.461: E/AndroidRuntime(3438):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2249)
10-15 10:08:43.461: E/AndroidRuntime(3438):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
10-15 10:08:43.461: E/AndroidRuntime(3438):     at android.app.ActivityThread.access$700(ActivityThread.java:154)
10-15 10:08:43.461: E/AndroidRuntime(3438):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
10-15 10:08:43.461: E/AndroidRuntime(3438):     at android.os.Handler.dispatchMessage(Handler.java:99)

EDIT : the solution that i adopted:

I changed the dimension. i make 5 set of image ( for the drawable folders) for every screen density. " is not useful use a 4mb's image if the device use at least the 50% of the size".

Luke
  • 517
  • 10
  • 29

2 Answers2

2

You said your image has the size of 2667 x 4733 pixels. Since this image will be turned into a Bitmap when being displayed, this is too large (in terms of pixels) and will cause your device to run out of memory.

A 32bit Bitmap of that size will use up 50 MB of RAM.

I recommend to reduce the size of the image drastically and make use of the different resource folders for image sizes. drawable-mdpi, etc.

Also, you can take a look at this question: High resolution Image - OutOfMemoryError

It deals with handling and loading large size images properly.

Community
  • 1
  • 1
Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
  • i can't reduce the quality of my image, i'll try with the method from the question you've posted – Luke Oct 15 '14 at 08:56
  • but, how i get a Resources type? ( in the method decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) ). i search here http://developer.android.com/guide/topics/resources/available-resources.html , but all methods return a int type.. – Luke Oct 15 '14 at 09:16
  • Drawable d = new BitmapDrawable(getResources(),bitmap); Layout.setBackgroundDrawable(d); – Philipp Jahoda Oct 15 '14 at 10:17
0

Check name of image. You may not use the name with : uppercase, - , * , and start with number.

MilanNz
  • 1,323
  • 3
  • 12
  • 29