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");
WHY do you you need a byte array ? (without any context, it's an xy problem)
and both methods don't do the same thing. the former is producing a png representation in memory, the latter returns pixels only.
i need byte array for processing the image.how should i go about it?
not an answer to my question.
which problem are you trying to solve here ?
and you probably should NOT do any processing on a per-pixel level, but use opencv or the like.
Its my assignment.where i have to perform encryption at pixel level.
public class POB_enc {
ah, ok (that was the answer....)
so, read up the docs on ImageIO.write again, its probably not what you want or need.
so cant i use opencv for reading pixel from image and reconstructing image in this case
what ? it's the other way round. if you would try with ImgIO.read(), you would have to decode the image first
please clarify, if you want to do this at file or at pixel level.
i want to run the above code on every pixel