Android Question manipulate width and height of a bitmap

Basco

Member
Licensed User
Longtime User
Hello everybody,

I have an a little problem I don't manage to solve..

I have a bitmap. I know how to get its size with Bitmpaname.width or Bitmapname.height, but when I want to use them (see code below), it crashes.

I think there is some of bitmap size property a missed...

B4X:
Bitmpaname = web(i).Bitmap
Msgbox("" & Bitmpaname.Height & "+" & Bitmpaname.Width,"")     'it works
If Bitmpaname.width < Bitmpaname.height Then    'my application stops here
      web(i).Bitmap = CreateScaledBitmap(web(i).Bitmap,120dip*x,120dip)
End If
If Bitmpaname.width > Bitmpaname.height Then
      web(i).Bitmap = CreateScaledBitmap(web(i).Bitmap,120dip,120dip/x)
End If
'x is a scaling factor, just for the example

Thank you a lot in advance for your help.

A beginner,

Basco
 

Basco

Member
Licensed User
Longtime User
Thanks for your reply. Maybe an idiot question but.. where do I find the log file ? I know I have a window called "log" on B4A but it is just writen that my device is connected, no more.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
You can also unfilter the log, as quite a lot of the information is suppressed, as you'll see when you unfilter it!

Alternatively generate the code in debug and then step through it, to the point where it crashes.


Obvious things to check are divide by zero etc...
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I think I see the error, width looks like it's in lowercase in your code, but above that it's got an upper case W, i.e. Width...

That looks like the culprit.
 
Upvote 0

Basco

Member
Licensed User
Longtime User
I will try your answer at home (I'm at work). Eps I think it's not due to upper case, it's just a bad copy/paste I did in my first post.. (I checked and it's Width in my code)

I'm not sure but I know that Bitmapname.width and Bitmapname.height are read-only. Does it mean that I can't compare them such as

B4X:
If Bitmpaname.width < Bitmpaname.height then

or use them to do operations such as

B4X:
dim a as int
dim b as int '<> 0
dim r as double
a = Bitmpaname.Width
b = Bitmpaname.Height
r = a/b

?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Is it definitely the If statement that it's failing on and not the next one?

Maybe comment out the logic and try the code inside the if statement on it's own? Just to rule that out.

I'm also not entirely sure about the DIP part of that code, I think it may well give you unexpected results. I do something similar in an App of mine, but it just uses actual values of screen width not DIP. But this depends on you getting to that statement as opposed to the IF part..
 
Upvote 0

Basco

Member
Licensed User
Longtime User
Yes it is definitely at the if statement it crashes. I expect a crash too at the next line, but now I just want to know why it crashed at the if statement.
An other thing.. If I add a line such as "a = Bitmpaname.Width" just before the if statement, with a defined as int, it crashes too. It could be a variable problem but I don't manage to find which problem..
 
Upvote 0

eps

Expert
Licensed User
Longtime User
My App is a little different, I only have landscape images in it, so it's not quite the same as yours.

It could be that another issue is making the If fail, but for a different reason, i.e. sub not ended properly, etc..

You'll really have to check the logs
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Basco,

just my 2 cents in. Could it be that web(i).Bitmap is null?

Umberto
 
Upvote 0

Basco

Member
Licensed User
Longtime User
I don't find the log... I've read somewhere that some phones have log diseable. Maybe it' my case (or I don'y realy know where to search...).
The log window just displays "--------- beginning of /dev/log/main"
I have checked and web(i).Bitmap is not null. I keep searchhing...
 
Upvote 0

Basco

Member
Licensed User
Longtime User
Thanks NJDude. I feel like... idiot..
NowI know what is the problem, my bitmap is not initialized. It says "java.lang.RuntimeException: Object should first be initialized (Bitmap)."
 
Reactions: eps
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…