How to convert a bitmap or byte array to an image?

hyunwookcho

My app, when user click capture button, start camera capture.

I use bitmap API. but sometimes memory problem. so I want use Glide library.

current my source

//Run on Preview call from Camera
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
  YuvImage image = new YuvImage(data, previewFormat, 640, 480, null);

  Rect rect = new Rect(0, 0, 640, 480);
  ByteArrayOutputStream bao = new ByteArrayOutputStream();
  image.compressToJpeg(rect, 100, bao); //Compress data in YUY2 format into a rectangular area in jpeg format.

  byte[] jpeg = bao.toByteArray();
  BitmapFactory.Options options = new BitmapFactory.Options();
  options.inPreferredConfig = Bitmap.Config.RGB_565;

  Bitmap convertedImage = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length, options); //byte array to bitmap

  mCallback.imageTaken(Bitmap.createScaledBitmap(convertedImage, 480, 360, true));
}

imageTaken(CaptureView.class)

   //completed capture picture.
   public void imageTaken(Bitmap bitmap) {
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);

      displayImage(bitmap); //preview bitmap image.
   }

displayImage(CaptureView.class);

public class CaptureView extends View implements CaptureViewer {

   private Bitmap mBitmap = null;
   private Rect src = new Rect(120, 96, 342, 272);
   private Rect dst;
   private int viewWidth, viewHeight = 0;

   @Override
   protected void onMeasure(int width, int height) {
      super.onMeasure(width, height);
      viewWidth = getLayoutParams().width;
      viewHeight = getLayoutParams().height;

      dst = new Rect(0, 0, viewWidth, viewHeight);
   }

   @Override
   public void displayImage(Bitmap image) {
      if (mBitmap != null) {
          mBitmap.recycle();
      }
      mBitmap = null;
      mBitmap = Bitmap.createBitmap(image);
      postInvalidate();
  }

  @Override
  protected void onDraw(Canvas canvas) {
     super.onDraw(canvas);
     canvas.drawBitmap(mBitmap, src, dst, null);
  }
}

this source work, but I want use Glide library. most of the examples, use url glide library.

but I want bitmap to image glide library.

How to convert a bitmap or byte array to an image using glide android?

Meenal

I think using below code you can get bitmap

Glide.with(this)
    .asBitmap()
    .load(path)
    .into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
            imageView.setImageBitmap(resource);
        }
    });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to convert Byte array into bitmap image?

From Dev

How to convert Bitmap image to byte array in wp7?

From Dev

Convert byte array or Bitmap to Picture

From Dev

RxJava convert byte array to Bitmap

From Dev

how to create a bitmap image from the byte array in swift

From Dev

ScalaFX: How to convert an Image object to a byte array

From Dev

How to convert byte array to buffered image

From Dev

How to convert byte array to image in javascript

From Dev

ScalaFX: How to convert an Image object to a byte array

From Dev

Convert byte array to Image

From Dev

Get bitmap from .DLL, convert to byte[] and to image

From Dev

Converting Bitmap Image to Byte Array and Store into Mysql

From Dev

Convert Bitmap from array of bytes (byte[]) - Bitmap is still null

From Dev

How to convert raster byte array of an image to original image in java?

From Dev

Convert PIL Image to byte array?

From Dev

Convert image to byte array quickly

From Java

How to create bitmap from byte array?

From Dev

How to create bitmap from byte array?

From Dev

How to Convert Byte Array to Image inside in Linq output List

From Dev

c# How to convert pictureBox.Image to Byte Array?

From Dev

How to convert a byte-array to a Image in C#?

From Dev

How to convert a .bmp image into Byte array using C Program

From Dev

How can I convert a image into a byte array in uwp platform

From Dev

How Can I Convert My new Byte Array To an Image

From Dev

How to convert a .bmp image into Byte array using C Program

From Dev

c# How to convert pictureBox.Image to Byte Array?

From Dev

How to convert UIImagePicker image into a byte array objective-c

From Dev

How to convert the bitmap image to mat image

From Dev

How to convert the bitmap image to mat image

Related Related

  1. 1

    How to convert Byte array into bitmap image?

  2. 2

    How to convert Bitmap image to byte array in wp7?

  3. 3

    Convert byte array or Bitmap to Picture

  4. 4

    RxJava convert byte array to Bitmap

  5. 5

    how to create a bitmap image from the byte array in swift

  6. 6

    ScalaFX: How to convert an Image object to a byte array

  7. 7

    How to convert byte array to buffered image

  8. 8

    How to convert byte array to image in javascript

  9. 9

    ScalaFX: How to convert an Image object to a byte array

  10. 10

    Convert byte array to Image

  11. 11

    Get bitmap from .DLL, convert to byte[] and to image

  12. 12

    Converting Bitmap Image to Byte Array and Store into Mysql

  13. 13

    Convert Bitmap from array of bytes (byte[]) - Bitmap is still null

  14. 14

    How to convert raster byte array of an image to original image in java?

  15. 15

    Convert PIL Image to byte array?

  16. 16

    Convert image to byte array quickly

  17. 17

    How to create bitmap from byte array?

  18. 18

    How to create bitmap from byte array?

  19. 19

    How to Convert Byte Array to Image inside in Linq output List

  20. 20

    c# How to convert pictureBox.Image to Byte Array?

  21. 21

    How to convert a byte-array to a Image in C#?

  22. 22

    How to convert a .bmp image into Byte array using C Program

  23. 23

    How can I convert a image into a byte array in uwp platform

  24. 24

    How Can I Convert My new Byte Array To an Image

  25. 25

    How to convert a .bmp image into Byte array using C Program

  26. 26

    c# How to convert pictureBox.Image to Byte Array?

  27. 27

    How to convert UIImagePicker image into a byte array objective-c

  28. 28

    How to convert the bitmap image to mat image

  29. 29

    How to convert the bitmap image to mat image

HotTag

Archive