How to set bitmap to ARGB_8888 in android?

bitmap android
android create bitmap
android bitmap density
android bitmap rgb
android hardware bitmaps
bitmap dependency in android
android java bitmap config
android bitmap bit depth

In my android project, I load a bitmap from a image in the phone. I then do various image manipulations to it like cropping, resizing, editing pixel values.

But the problem is the format of the bitmap is not ARGB_8888, so its not really storing the alpha values. Or rather its always keeping them at 255.

How can I load the bitmap in ARGB_8888 format? This is my code to load and resize. How can I specify the format in any of these?

Thanks

private static Bitmap resize(Bitmap img, int newW, int newH) throws IOException {
    Bitmap resizedImg = Bitmap.createScaledBitmap(img, newW, newH, false);
    img.recycle();

    Bitmap newresizedImg = resizedImg.copy(Bitmap.Config.ARGB_8888, true);
    resizedImg.recycle();


    Pixel initialPixel = Function.getPixel(0, 0, newresizedImg, null);
    int a = initialPixel.getColor().getAlpha(); // -> 255
    newresizedImg.setPixel(0, 0, Pixel.getTransparentColor().getRGB());
    initialPixel = Function.getPixel(0, 0, newresizedImg, null);
    int new_a = initialPixel.getColor().getAlpha(); // -> 255

    return newresizedImg;
}

private static Bitmap getImage(String from) throws IOException {
    File file = new File(from);

    if (file.exists()) {
        BitmapFactory.Options op = new BitmapFactory.Options(); 
        op.inPreferredConfig = Bitmap.Config.ARGB_8888; 
        Bitmap bufferedImage = BitmapFactory.decodeFile(from, op);
        return bufferedImage;
    }
    return null;
}

Pixel class

public static Color getTransparentColor() {
    return new Color(0, 0, 0, 0);
}

Color class

public int getRGB() {
    return ((A << 24) | 0xFF) + ((R << 16) | 0xFF) + ((G << 8) | 0xFF) + (B | 0xFF);
}

You can copy your bitmap using this type of function (or you know, not use a function depending on how you want to use it)

private Bitmap ARGBBitmap(Bitmap img) {
  return img.copy(Bitmap.Config.ARGB_8888,true);
}

java - How to set bitmap to ARGB_8888 in android?, You can copy your bitmap using this type of function (or you know, not use a function depending on how you want to use it) private Bitmap ARGBBitmap(​Bitmap  Question Description. I am trying to access the raw data of a Bitmap in ARGB_8888 format on Android, using the copyPixelsToBuffer and copyPixelsFromBuffer methods. However, invocation of those calls seems to always apply the alpha channel to the rgb channels.

BitmapFactory.Options op = new BitmapFactory.Options(); op.inPreferredConfig = Bitmap.Config.ARGB_8888; bitmap = BitmapFactory.decodeFile(path, op);

from: How can I specify the bitmap format (e.g. RGBA_8888) with BitmapFactory.decode*()?

Bitmap.Config, Config, ARGB_8888. Each pixel is stored on 4 bytes. Bitmap.Config, HARDWARE. Special configuration, when bitmap is stored only in graphic  Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); A bitmap is simply a rectangle of pixels. Each pixel can be set to a given color but exactly what color depends on the type of the pixel. The first two parameters give the width and the height in pixels. The third parameter specifies the type of pixel you want to use. This is

You can use this:

public Bitmap highlightImage(Bitmap src) { 
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth() + 96, src.getHeight() + 96, Bitmap.Config.ARGB_8888); 
    return bmOut;
}

Loading Large Bitmaps Efficiently, Deprecated: Because of the poor quality of this configuration, it is advised to use ARGB_8888 instead. Each pixel is stored on 2 bytes. The three  I am trying to access the raw data of a Bitmap in ARGB_8888 format on Android, using the copyPixelsToBuffer and copyPixelsFromBuffer methods. However, invocation of those calls seems to always appl

Hope this helps as this works for me.

Bitmap bitmap = Bitmap.createBitmap(marker.getMeasuredWidth(), marker.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

Java Code Examples android.graphics.Bitmap.Config, Read Bitmap Dimensions and Type; Load a Scaled Down Version into for the full image (assuming a bitmap configuration of ARGB_8888 ). Get rgba uint8[] from ARGB_8888 bitmap. Ask Question How to set a bitmap from resource. 3. android bitmap pixel format for glTexImage2D. 0.

android.graphics.Bitmap.eraseColor java code examples, This page provides Java code examples for android.graphics.Bitmap.Config. ARGB_8888); Canvas canvas = new Canvas(createBitmap); Paint paint = new Paint(); Rect rect2 = new setBitmap(result); // Draw ambient shadow mDrawPaint. I am trying to create a Bitmap in Android using the Bitmap.Config.ARGB_8888 after I have received the bytes from an external source. As I understand the fastest way to set raw bytes in a Bitmap (without using JNI) is by using the copyPixelsFromBuffer() method, however the question arises regarding the correct order of the bytes in that buffer.

android.graphics.Bitmap.createBitmap java code examples, ARGB_8888, true); canvasBitmap.eraseColor(0x00000000); // Create canvas Canvas canvas = new Canvas(canvasBitmap); // Create rotation matrix Matrix  I'm getting a byte array from NDK in RGBA format. I need to flush the byte array to a Bitmap (to show in ImageView or Surface). I would like to use: Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bm.copyPixelsFromBuffer(ByteBuffer.wrap(buffer)); But can't find a way to convert the RGBA to ARGB_8888 format. Any ideas?

tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java , @Test public void testLoadBitmap_asDrawable() { Bitmap bitmap = Bitmap.​createBitmap(100, 100, Bitmap.Config.ARGB_8888); requestManager .load(​bitmap)  I've used the format method but the Images are still losing the quality. Is there any other option to download the image as a 100% JPG? Actually I'm not sure if this is a problem with Glide or PhotoView zooming (still checking this), so a good test would be to download the images to the cache and open them outside my app.

Comments
  • What file format you reading into it? I've used code very similar to yours above with great success. What file format? Can you perhaps provide a sample of the image you're having issues with? Have you stepped through the function with a debugger to check all the getPixel functions to make sure they're returning the results you expect?
  • I think I lose the Alpha support when I resize it. How can I fix it?
  • It shouldn't lose Alpha 'support' what's the code you used for resizing?
  • Umm stupid me. Well you are creating a new Bitmap which hasn't got that setting yet.
  • How can I specify that setting when I resize it?
  • Isn't there a fourth parameter for a Bitmap.Config... when creating the resized image?
  • Why the +96 height and width?
  • Not necessary to use +96. I have use that to scale the image.It's necessity purpose.
  • Oh it's an example my bad