For a current project I need to know which method is faster:
Bitmap.createBitmap(width,height,config)
or
BitmapFactory.decodeResource(getResources(),id)
thanks for your support
I usually ask questions on sites like this because I hope there are some people who may have experienced the same situation or asked themselves the same question as I do. But more and more i recognised that simple questions like the above one,are obviously not wanted here.
The answer for my question is:
Loading Bitmaps is not as fast( and thus efficient) as creating a new one
Thanks for the great help and suggestions
I upvoted your answer but it's important to note that these methods are not interchangeable, as some people may assume from the question.
AFAIK, BitmapFactory.decodeResource() is used to instantiate a Bitmap from a resource (e.g. a .png or .xml in the drawable directory),
While Bitmap.createBitmap() is used to instantiate a brand enter code herenew Bitmap (basically from primitives such as float etc), so i don't see how they could be interchangeably used, and hope i saved future readers from scratching their heads a little.
Related
I have to deal with images in the format given above. However, I have found conflicting information about it.
According to another stack overflow answer the UV values follow eachother, while according to Wikipedia the V values lie AFTER the U values in memory. Which one is correct, or if they both are, what is the difference?
Could it be a NV12 vs NV21 problem? However, this site states that they should simply be switched.
Maybe it has something to do with the image being planar, semi-planar or not planar, though I have no idea what these terms mean.
Can someone clarify this a bit?
For NV21, the order is V/U. The Wikipedia description of NV21 is correct.
The diagram in the StackOverflow response you cited has an error. A couple people in the comments pointed this out.
I have a question concerning data storage in android and hope to get some help here. I've tried searching for it, but couldn't find anything specific to my question. Please feel free to point me in the right direction, if I missed something.
I'm very new to android programming, having mostly experience in C++ and C#.
For my first project I picked something small. I want to programm an app for my wife and me, which manages the contents of our freezers. ;) It's simple. You create a freezer, define a certain amount of compartments and then add content to those compartments, which contain certain attributes (food type, amount, weight, expiration date etc).
Now, obviously this "database" will not contain a hell of a lot of info. Maybe 50 items tops? So from what I gathered XML might be a good way to go.
However, this data will be modified quite often. Things will be added, removed, modified, moved from one compartment to another. Would sqlite be a better choice in that situation?
I would greatly appreciate any advice you guys and girls might have. Again, small database, lots of modifications along the way ... XML or sqlite?
Thanks a lot in advance. :)
Michael
Although XML will work, but in terms of modification (change the data) and persistence (write to disk), it is certainly not as easy as SQLite.
With XML, you are constantly dealing with the entire document, even when you just want to deal with a little piece of it.
I found the API dealing with XML are quite often not so intuitive.
To be honest, XML has already passed its most glorious time. At one point, people express virtually everything as Xml whenever they had a chance. But that time has passed, and that's clearly not the situation any more.
Growing is a major consideration here too. I understand that it is small, but the size is one side, and the structure is the other side, XML is less flexible in terms how much code change you need to make when the structure of data changes.
I knw this is one of the most discussed question but I couldn't figure out my way with the questions available here.
I'm decoding the bitmap as below
BitmapFactory.decodeFile(sdCardPath);
While executing above line randomly system running out of memory. This is not happening always . For example if I try to decode same image 3 times, it might go out of memory 3rd time or even 4th time. This error observed randomly.
How to solve this issue??
Thanks for your time in advance
First, if this is a bitmap that you are referencing from your assets, I would recommend moving it to your res/drawables folder, and access it as a drawable. If this is not the case, you are making too many references to this image without, as #VargaPeter pointed out, garbage collecting. The best way to garbage collect when using multiple bitmaps is to call recycle(), however System.gc() is often used as well (though in practice, you should use recycle(). If you are still having problems, you must either (a) allocate more space using the Android NDK (discouraged), or (b) use a smaller bitmap image (recommended). I know for certain there are posts discussing option b in several places on this site, as I had this same problem once before.
The Bitmap that you get back probably isn't garbage-collected because of a lingering reference.. Try to use the same reference if the app's design allows, or reusing a small number or references...
Im currently developing a software under android and im getting quite quickly some OutOfMemoryException.... I did modified some part of my code to use more static variables instead of making new allocation with the "new" operator but is there any things else to do ? or any other tips ? Any advices would be welcome.
Thanks.
You can find a lot of tips here: http://developer.android.com/guide/practices/design/performance.html
Especially look at the Avoid Creating Objects topic.
You can also watch some Google I/O conferences, like the ones about writing non-janky apps or how to make fast and efficient apps from 2009.
If you have some resources that can be reloaded onto memory anytime, consider using WeakReferences. The objects inside them will be cleared just before the (Java) VM throws OutOfMemoryException, so there will be some more memory available.
You may be accessing too many resources (such as images) before garbage collector can handle/recycle them. If you're accessing particularly large images, then use BitmapFactory to scale them down, as seen answered on SO. (Of course, for this you would see something like "bitmap size exceeds vm budget" in your logcat too.)
Any more details on the error?
Long time reader never posted until now.
Im having some trouble with Android, im implementing a library called JJIL its an open source imaging library.
My problem is this i need to run some analysis on an image and to do
so i need to have it in jjil.core.image format and once those
processes are complete i need to convert the changed image from
jjil.core.image to java.awt.image.
I cant seem to find a method of doing this does anyone have any ideas
or have any experience with this?
I would be grateful of any help.
Danny
You should let others know what you found... probably you found that android.graphics.Bitmap has a getPixel(x,y) method that returns an int representing the ARGB value?
http://developer.android.com/reference/android/graphics/Bitmap.html
I have done some serious research into this and i have found that i can extract the rgb values of a bitmap image with a similar method.
But the threshold that i was using the previous library for is now not possible because i have had to abandon the use of this library.
Is there a way to use colour matrix's to threshold the image? Or better still is there an inbuilt method that would do this automatically?
Thank you for any help.
Danny