Ask Your Question

Revision history [back]

which one is best method to read image and convert it into byte array in java and opencv

I'm trying to generate byte array from image for that i tried two different method but i'm not understanding which one is better because both method require so much time

so if any alternative available please suggest

Java code :

    File newfile = new File(path);
    BufferedImage originalImage = ImageIO.read(newfile);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(originalImage, "png", baos);
    imageInByte = baos.toByteArray();

Opencv method which i tried :

Mat originalImage=  Highgui.imread(path);
byte[] imageInByte = new byte[(int) (originalImage.total() * originalImage.channels())];
originalImage.get(0, 0, imageInByte);
System.out.println("CONVERTED TO BYTE");
click to hide/show revision 2
retagged

updated 2018-06-10 01:23:50 -0600

berak gravatar image

which one is best method to read image and convert it into byte array in java and opencv

I'm trying to generate byte array from image for that i tried two different method but i'm not understanding which one is better because both method require so much time

so if any alternative available please suggest

Java code :

    File newfile = new File(path);
    BufferedImage originalImage = ImageIO.read(newfile);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(originalImage, "png", baos);
    imageInByte = baos.toByteArray();

Opencv method which i tried :

Mat originalImage=  Highgui.imread(path);
byte[] imageInByte = new byte[(int) (originalImage.total() * originalImage.channels())];
originalImage.get(0, 0, imageInByte);
System.out.println("CONVERTED TO BYTE");
click to hide/show revision 3
retagged

updated 2018-06-10 01:24:00 -0600

berak gravatar image

which one is best method to read image and convert it into byte array in java and opencv

I'm trying to generate byte array from image for that i tried two different method but i'm not understanding which one is better because both method require so much time

so if any alternative available please suggest

Java code :

    File newfile = new File(path);
    BufferedImage originalImage = ImageIO.read(newfile);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(originalImage, "png", baos);
    imageInByte = baos.toByteArray();

Opencv method which i tried :

Mat originalImage=  Highgui.imread(path);
byte[] imageInByte = new byte[(int) (originalImage.total() * originalImage.channels())];
originalImage.get(0, 0, imageInByte);
System.out.println("CONVERTED TO BYTE");