Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert bitmap to drawable

 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I want to resize my drawable image and assign it into ImageView but i couldn't do it.
What i want is get image which located in drawable folder and resize it due to screen width and assign into ImageView.

I really appreciate for any help.

Regards
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what i use but app crash as soon as reach to decodeResource

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the stack trace of the exception.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ulf

here is the logcat output

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is "unscaledBitmap" valid? Or is it null?
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i edit code sometimes it says it is null.
sometimes it crashes.

I am not sure when it crash and when it became null because i edited code soooooo many times.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if it's null, then obviously the call to createScaledBitmap can't succeed, and since the code doesn't handle exceptions, it crashes.

The javadocs of the "inJustDecodeBounds" option explain why this is happening.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ulf

The problem is i am using 2 different image view
one is 1200 x 1200 px about 800kb
and another one is 1012 x 1012 px about 650kb

What i want here is that, i want to support every screen resolution but app works in tablet and not in smart phone.

So, i decided to resize those pictures but somehow i am keep failing.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you change in response to the 2nd sentence of my previous reply? It advised you to read those javadocs; did you do that? If so, what did you learn about that option? If not, start with that.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Ulf
when i post last reply it was almost 3am (i guess) in here.
So, i am reading it now. If something goes weird i write it down here.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ulf



it works now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic