Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

DNPereira

[Resolvido] [Android] OutOfMemoryError

Recommended Posts

DNPereira

try {
open1 = manager.open(LayoutOne.Info.get(LayoutOne.e)+File.separator+LayoutTwo.theme.get(LayoutTwo.r)+File.separator+"Background.jpg");
bMap = BitmapFactory.decodeStream(open1).copy(Bitmap.Config.ARGB_8888, true);
BackGround.setImageBitmap(null);
BackGround.setImageBitmap(bMap);
} catch (IOException e1) {
e.printStackTrace();
}

Erro

E/AndroidRuntime(5929): FATAL EXCEPTION: main
E/AndroidRuntime(5929): java.lang.OutOfMemoryError
E/AndroidRuntime(5929): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime(5929): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:574)
E/AndroidRuntime(5929): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:640)
E/AndroidRuntime(5929): at com.LayoutThree.onCreate(LayoutThree.java:155)

não estou a conseguir resolver. porque quando tento colocar novas imagens nos bitmaps ele não deixa e dá esse erro de memoria

obrigado

Edited by DNPereira

Share this post


Link to post
Share on other sites
KTachyon

A imagem que estás a carregar tem que dimensões? Seria um dado útil para o problema. De qualquer forma, acredito que seja uma imagem de grandes dimensões. Quando o bitmap é criado, vais estar a ocupar 4 bytes por pixel (3 cores + alpha), o que no caso de uma imagem de 8 MP dá qualquer coisa como 32 MB.

Aconselho a leitura dos tópicos apresentados na seguinte página:

http://developer.android.com/training/displaying-bitmaps/index.html

  • Vote 1

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.