Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java

Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java - welcome to our blog that presents the full content How Gadget, the discussion this time we're discussing that you find that Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java, we have provided complete information with images that are easy to understand, the explanation is simple but complete, therefore please read until the end :)

This is about : Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java
And this article : Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java

You can also see our article on:


    Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java

    Hi techies,

    Now iam gonna share a wonderful and efficient way on "How to convert IplImage to byte array in JavaCV" with pure java code.



    How to convert IplImage to Android Bitmap

    public static Bitmap IplImageToBitmap(IplImage src) {
    Bitmap bm=null;
       int width = src.width();
       int height = src.height();
    // Unfortunately cvCvtColor will not let us convert in place, so we need to create a new IplImage with matching dimensions.
    IplImage frame2 = IplImage.create(width, height, opencv_core.IPL_DEPTH_8U, 4);
    opencv_imgproc.cvCvtColor(src, frame2, opencv_imgproc.CV_BGR2RGBA);
                       // Now we make an Android Bitmap with matching size ... Nb. at this point we functionally have 3 buffers == image size. Watch your memory usage!
    bm = Bitmap.createBitmap(frame2.width(), frame2.height(), Bitmap.Config.ARGB_8888);
    bm.copyPixelsFromBuffer(frame2.getByteBuffer());
    //src.release();
    frame2.release();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] byteArray = stream.toByteArray();
    return bm;
    }


    How to convert IplImage to byte[]

    public static byte[] IplImageToByteArray(IplImage src) {
    Bitmap bm=null;
        int width = src.width();
        int height = src.height();
     // Unfortunately cvCvtColor will not let us convert in place, so we need to create a new IplImage with matching dimensions.
      IplImage frame2 = IplImage.create(width, height, opencv_core.IPL_DEPTH_8U, 4);
      opencv_imgproc.cvCvtColor(src, frame2, opencv_imgproc.CV_BGR2RGBA);
                        // Now we make an Android Bitmap with matching size ... Nb. at this point we functionally have 3 buffers == image size. Watch your memory usage!
      bm = Bitmap.createBitmap(frame2.width(), frame2.height(), Bitmap.Config.ARGB_8888);
      bm.copyPixelsFromBuffer(frame2.getByteBuffer());
      //src.release();
      frame2.release();
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
      return stream.toByteArray();
    }

    So hope you guys got this helper methods so useful for your JavaCV projects.
    And don't forget to use the comment box below.


    Information Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java has been completed we present

    A few of our information about the Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java, we hope you benefit from this article

    You have just read the article Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java and many articles about gadget in our blog this, please read it. and url link of this article is https://howtomonetizeeverything.blogspot.com/2015/05/convert-iplimage-to-byte-array-or.html Hopefully discussion articles on provide more knowledge about the world of tech gadgets.

    Tag :

    Related Posts :

    0 Response to "Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java"

    Post a Comment