Results 1 to 5 of 5
  1. #1
    alex88 is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default Replace a region of an image

    Hi guys, i've to do a parallel image processing, i'm making the basics of that, so i've created a function that returns a region of a jpeg file as bufferedImage, this way:

    Java Code:
    BufferedImage image = readImg("/Users/alessandro/Documents/image.jpg", 0,0,8,8);
    That will return the image region starting at (0,0) having width and height as 8px.

    Now after processing (converting or what else) i've lot of these chunks to reassemble in the final image, i've managed to create an empty image having the same size of the original one (as jpeg) and i'm trying to replace block by block the regions of the final image with this code:

    Java Code:
    public static void writeImg (String path, int startx, int starty, BufferedImage image){
    		File output = new File(path);
    		ImageOutputStream ios = null;
    		try {
    			ios = ImageIO.createImageOutputStream(output);
    		} catch (IOException e){
    			e.printStackTrace();
    		}
    		Iterator iter = ImageIO.getImageWritersByFormatName("BMP");
    		ImageWriter writer = (ImageWriter)iter.next();
    		writer.setOutput(ios);
    		
    		try{
    			if(writer.canReplacePixels(0)){
    				System.out.println("True");
    			}else{
    				System.out.println("False");
    			}
    		}catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    		ImageWriteParam param = writer.getDefaultWriteParam();
    		Point destinationOffset = new Point(startx,starty);
    		param.setDestinationOffset(destinationOffset);
    		try {
    			writer.replacePixels(image, param);
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    the problem is that

    Java Code:
    writer.replacePixels(image, param);
    throws "java.lang.UnsupportedOperationException: Unsupported write variant!" and i've no idea why and how could i fix this error, any idea?

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    If you read the API for ImageWriter, you'll notice that 'replacePixels' is an optional feature that throws UnsupportedOperationException if it's not supported. The ImageWriter you are using doesn't support 'replacePixels', so you'll have to find another way.

    I suggest forming the output image as a BufferedImage, and not writing it out until it's complete.

  3. #3
    alex88 is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    Thank you for response, bytheway that's the problem, the final image (as the source one) is too big to fit in memory, i wanted to do that on a cluster using map reduce, and assign each worker the operation to get its own block, process it and write the result.

  4. #4
    zahariesergiu is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    hello Alex, i have the same problem,did you resolve it?
    please let me now. Thank you!

  5. #5
    alex88 is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    Not really i'm sorry, you should check at JPEGclub.org to see some source in C and probably with that it can be done without decoding the full image.

Similar Threads

  1. Multiple JButtons in BorderLayout region.
    By VisionIncision in forum AWT / Swing
    Replies: 3
    Last Post: 01-02-2011, 11:28 PM
  2. How to replace int with asterisk
    By erin.ctm in forum New To Java
    Replies: 3
    Last Post: 11-12-2010, 11:13 PM
  3. is there anyway to replace java.IO
    By nobody58 in forum Advanced Java
    Replies: 1
    Last Post: 03-19-2010, 01:19 PM
  4. Change color of a region
    By sky in forum AWT / Swing
    Replies: 5
    Last Post: 11-24-2009, 03:47 PM
  5. Using a replace method...
    By paul in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 04:50 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •