문제

I am trying to get the length of an image as well as the length of a portion of it, but both give the same result. Where did I go wrong?

Part of area of image:

private BufferedImage add_text(BufferedImage image, String text) {
    BufferedImage imageLocation=image.getSubimage(image.getWidth()/2, image.getHeight()/2, 
            image.getWidth()-image.getWidth()/2, image.getHeight()-image.getHeight()/2);

    byte img[] = get_byte_data(imageLocation);
    System.out.println("Image length: "+img.length);

Whole image:

private BufferedImage add_text(BufferedImage image, String text) {

    byte img[] = get_byte_data(image);
    System.out.println("Image length: "+img.length);

The output of both is

Image length: 984900

도움이 되었습니까?

해결책

Here you are getting length of the byte array. Not the actual image. You should use imageLocation.getWidth() and imageLocation.getHeight().

If you have checked the java doc http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html it says that getSubimage method shares the same data array as the original image. That is why you are getting same length for the data array length.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top