How To Fill Bitmap Data in ARGB Format in Android LabelView - android

I'm working with Android and I really need a fast way to get a bitmap of format BGRA to be filled in ARGB.
One thing I aslo want to let u know that The Data comes in byte[] format and I have to convert in int[] format also.
Can AnyOne Tell me How to do this ...
Thanks in Advance

If you want to load a Bitmap by bytestream, you can use Bitmap.decodeStream. You could then use getPixel(s?) to get the int array. This is one way I know how to do this, probably not the fastest though. A faster way would be to convert bytes to int, if your byte array is nothing but pixeldata this won't be too hard.
BGRA to ARGB can be done with bitshifting quite fast.
A nice source you would probably like:
https://web.archive.org/web/20141229164101/http://bobpowell.net/lockingbits.aspx

The fastest way I think would be to do it in native code using the NDK. I've been considering to use it for image processing for some time but didn't get the chance yet. So I don't know much about it (i.e. how you would access your byte buffer) but you could start from the Plasma sample for bitmap processing in JNI.

Related

How do images in a property of an object work and setting them from bitmap?

A little bit of a backstory, I am currently an IOS developer transitioning into working with Android, more specifically Kotlin, and the way that Android Development handles images confuses the hell out of me!
Can someone please explain to me how/why images are saved as type Int and how can I set an image as a property on of my objects. I understand Drawables have Id's that are type Int and that I should save them that way, but I am currently trying to get an image from the user's gallery and the data from the Intent on the "onActivityResult" function comes back as an Intent for which I then convert to a bitmap.
SUMMARY: How do I properly work with Image properties in Kotlin (Int) and convert a bitmap to type Int to set my property?

Updating bitmap in ImageView with Chaquopy

I have been trying to graph data in Android using matplotlib through Chaquopy. So far, creating the plots themselves in Chaquopy has been very easy. However, I am unclear on exactly how to save the plot and load it into the ImageView. I looked at this example (How to display python matplotlib graphs (png) with Chaquopy in Android Studio), and that seems like a promising method, but it involves plotting in Python, storing the image as a bytes object, and then loading the bytes object into the ImageView in Java. Ideally, I would like to be able to do all of this, including updating the ImageView, from the python script. Is this possible?
Thanks for any help and advice!
Edit:
I found a solution that avoids the bytes object entirely:
root = Environment.getExternalStorageDirectory()
plt.savefig(root.getAbsolutePath() + "/fig1.png")
bitmap = BitmapFactory.decodeFile(root.getAbsolutePath() + "/fig1.png")
self.findViewById(R.id.imageView).setImageBitmap(bitmap)
If anyone has a solution using the bytes object though I would welcome any suggestions.

Android getDrawable performance

I have a question (hope it is not stupid). Is getDrawable(int resId) slow ?
And is it faster than decoding resource with BitmapFactory ? And is it faster to call getDrawable(resid).getInstrinsicHeight() than decoding with Bitmap.Options with inJustDecodeBounds = true and than get the width ? I know that decoding of bitmaps is slow, and they consume a lot of memory, but what about getDrawable(int redId) and the result Drawable object ? It is allocate a lot of memory.
Thanks in advance.
Your Question is Similar to this one :
Efficient way of creating Bitmap out of Drawable from res (BitmapFactory vs Type Casting)
"You can take a look at the source code for Bitmap factory at http://source.android.com specifically the code for decodeResource.
I would reason that using BitmapFactory is preferred but in either case if you are decoding multiple bitmaps then you should call getResources() once and store the result for use as the resources argument for the functions."
Further, i would recommend you to go through 1st 2 articles here, to learn about the workaround for using either of these effficiently :
http://www.coderzheaven.com/tag/getdrawable/

Android base64.decode() into existing byte array

On Android, I'm using Base64.decode() method. It has several variants, but all of them decode the given base64 input into a newly created byte array.
Since I need to call this a lot with big inputs, it allocates a lot of memory and causes frequent GC.
So I'm wondering if there is a way to pass an existing byte array to the method, or alternative techniques, so that it puts the result inside the existing byte array and avoid allocating memory for a new one.
That would be similar to the use of options.inBitmap in BitmapFactory when creating a bitmap in order to reuse an existing bitmap.
Thanks for your help

How to get mime type from a bitmap object in android?

I want to get mime type of a bitmap object.
Actually I have compressed a bitmap using
bitmap.compress (Bitmap.CompressFormat.PNG , 100, stream);
Now I want to cross check the format, outBounds and memory space size. But I don't wanna do a lengthy or a tedious task eg. to convert it to back to stream and then convert it again to BItmap using BitmapFactory with options.
Like Dmitry suggests, if what you have is a compressed image in a stream, then you do need to decode it using a BitmapFactory to tell what type it is. (Technically, you could also read the stream yourself and run your own ad hoc file format checks on it, but I assume you'd prefer to use existing tools rather than rolling your own.)
One optimization you can and should make is to set BitmapFactory.Options.inJustDecodeBounds to avoid needlessly decoding the entire image if you just want to know what type it is. After decoding, the outMimeType property should give you the type of the image.
As for the literal question in your title, it doesn't make sense. A Bitmap has no MIME type — it's just a container for an array of pixels. You can compress the bitmap into a stream using various formats, like JPEG, PNG or WEBP, but that just gives you a compressed copy of the image.

Categories

Resources