Reusing a bitmap

ukimiku

Active Member
Licensed User
Longtime User
I draw, through canvas c, into a (mutable) bitmap b. It gets displayed in image view i.

Now what I am trying to achieve is to resize bitmap b to get smaller or larger (user choice).

Any combination of commands I have tried has just resulted in another bitmap being created and drawn on top of the existing one. I can't have that as there may be many bitmaps created, which would use up too much device memory.

I have the feeling that the solution may have something to do with "recycling" bitmap b, but the post(s) I read on that topic have been eluding me. Do I have to remove the image view i from the activity? Do I have to set the reference to c, b, or i to "null"?

Thank you.

Regards,
 

agraham

Expert
Licensed User
Longtime User
Upvote 0

Informatix

Expert
Licensed User
Longtime User
You might want to include the reason why you can get an easily get an out of memory error and so need to recylce a bitmap rather than relying on the garbage collector - http://www.b4x.com/forum/basic4andr...6-loading-bitmap-woes-resolved.html#post69468

That's maybe too complex for the audience I'm writing for and, if I do, I should make a difference between the pre-Honeycomb memory management and post-Honeycomb MM (pixel data are no more in the native heap and the GC collects synchronously in only one cycle), and I should explain why the GC, supposed to run asynchronously with Gingerbread, stops your main thread when it collects bitmaps.
 
Last edited:
Upvote 0

ukimiku

Active Member
Licensed User
Longtime User
Interesting. You don't have to include that into your tutorial, now that I know it... :eek: Who is your intended audience? Have you written a lot so far? Gotten some feedback from your intended audience?

I think a tutorial is a good idea, especially when it is targeted at beginners and not so much at prospective users of library xy.

And I think that you should at least mention the need to recycle bitmaps under certain circumstances. Those bugs can be difficult to trace. If you include maybe 7 or eight lines of code in your tutorial, and annotate them, it should suffice as an outlook for novices (I know that because despite my flattering designation as "Senior Member", I am still a novice with many topics regarding B4A. Maybe it's misspelled and was supposed to read "Senor Member", as a welcome to novice Spanish-speaking members).

Regards,
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Who is your intended audience?
Beginners that already know the basics and are able to create a simple application.
I'm not a B4A expert and cannot write for advanced users.

Have you written a lot so far? Gotten some feedback from your intended audience?
I've written four tutorials until now. "How do they... ?" 1 to 4.
The feedback is very good, as you can see in the comments.

I think a tutorial is a good idea, especially when it is targeted at beginners and not so much at prospective users of library xy.
All my tutorials mention and use my own classes and libraries. I didn't do that to sell something (everything is free). I did it because I'm in the best position to talk about them. And because you need these classes and libraries to do advanced UIs (or you can lose weeks trying to do the same).

And I think that you should at least mention the need to recycle bitmaps under certain circumstances. Those bugs can be difficult to trace. If you include maybe 7 or eight lines of code in your tutorial, and annotate them, it should suffice as an outlook for novices
I will try to simplify the technical stuff (a lot of beginners don't know what's a native heap, a Java heap or a garbage collector) and give useful advices.
 
Upvote 0

ukimiku

Active Member
Licensed User
Longtime User
Thanks, I read your "How do they..." #4 tutorial (in French). I think you have a real talent for explaning complicated things in simple terms that are easy to grasp. :icon_clap:

I don't think that a tutorial of worth is necessarily targeted at advanced users. After a while of programming, most of us will certainly have a B4A area of expertise, and then, while not B4A allround-experts like Erel, could very well write a tutorial on what they understand and can do well. With all the helpfulness, friendliness, and resourcefulness here at the forum I imagine even jointly written and revised tutorials might be a possibility.

Moreover, I think it's great that you did it in French (which is, I suppose, your native language). There are some good resources for German-speaking B4A programmers, too, but a couple more tutorials like yours would be a welcome addition.

As for the copyright considerations, I in principle agree with Robert Garstang. But -- maybe because I have never (yet) developed applications that I wanted to sell :) -- I hold that copyright laws for immaterial goods based on premises conceived for material goods are both outdated and often abused as a means to suppress or even eliminate competition, and, in turn, better software.

Regards,
 
Upvote 0
Top