Results 1 to 5 of 5
Thread: Replace a region of an image
- 03-04-2011, 02:57 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
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:
That will return the image region starting at (0,0) having width and height as 8px.Java Code:BufferedImage image = readImg("/Users/alessandro/Documents/image.jpg", 0,0,8,8);
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:
the problem is thatJava 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(); } }
throws "java.lang.UnsupportedOperationException: Unsupported write variant!" and i've no idea why and how could i fix this error, any idea?Java Code:writer.replacePixels(image, param);
- 03-04-2011, 06:46 PM #2
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
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.
- 03-04-2011, 11:31 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
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.
- 06-04-2011, 04:08 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
hello Alex, i have the same problem,did you resolve it?
please let me now. Thank you!
- 06-04-2011, 05:21 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
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
-
Multiple JButtons in BorderLayout region.
By VisionIncision in forum AWT / SwingReplies: 3Last Post: 01-02-2011, 11:28 PM -
How to replace int with asterisk
By erin.ctm in forum New To JavaReplies: 3Last Post: 11-12-2010, 11:13 PM -
is there anyway to replace java.IO
By nobody58 in forum Advanced JavaReplies: 1Last Post: 03-19-2010, 01:19 PM -
Change color of a region
By sky in forum AWT / SwingReplies: 5Last Post: 11-24-2009, 03:47 PM -
Using a replace method...
By paul in forum New To JavaReplies: 2Last Post: 08-07-2007, 04:50 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks