![]() |
How to create image from integer pixels stored in array
My task includes reading a .jpg image, accessing the pixels, processing them and displaying the final image
the code is as follows: public static void main(String[] args) { BufferedImage sourceImage = null; try { sourceImage = ImageIO.read(new File("IScSH.jpg")); } catch (IOException e) { } int type = sourceImage.getType(); int w = sourceImage.getWidth(); int h = sourceImage.getHeight(); byte[] pixels = null; if (type == BufferedImage.TYPE_3BYTE_BGR) { System.out.println("type.3byte.bgr"); pixels = (byte[]) sourceImage.getData().getDataElements(0, 0, w, h, null); } try { BufferedImage edgesImage = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR); edgesImage.getWritableTile(0, 0).setDataElements(0, 0, w, h, pixels); ImageIO.write(edgesImage, "jpg", new File("nvRhP.jpg")); } catch (IOException e) { } } the above code works fine, but if I write something as, before the try block begins, for ( i = 0; i < data.length; i++) { data[i] = pixels[offset++] & 0xff; } i.e convert the byte array to integer array and then display the image it gives wrong output. The problem is, as I have to further process these pixels I have to convert them in integer values but then the result is wrong. Please help |
| All times are GMT +1. The time now is 07:05 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.