Forums Register Login

Tiling an image

+Pie Number of slices to send: Send
I'm currently trying to create a method which tiles an image into four smaller images in the same picture.

I have looked at how other people have attempted it like http://introcs.cs.princeton.edu/java/31datatype/Tile.java[2] but have no idea why it works or if " Picture input = new Picture(args[0]);" that part is even part of java api.

I have also looked at the methods such as getSubImage methods and they don't seem to work

This is what I have attempted so far:
public static BufferedImage divide(BufferedImage image) {
int height = image.getHeight() / 2;
int width = image.getWidth() / 2;
BufferedImage tile = image.getSubimage(50, 50, width, height);

return tile;

}

Can anyone help me fix this?
+Pie Number of slices to send: Send
 

I have looked at how other people have attempted it like http://introcs.cs.princeton.edu/java/31datatype/Tile.java[2] but have no idea why it works or if " Picture input = new Picture(args[0]);" that part is even part of java api.


It is not. Have you read the entire article that includes the source code for all involved classes?

they don't seem to work


What does this mean? What did you expect to happen, and what happened instead?
+Pie Number of slices to send: Send
 

Ulf Dittmer wrote:

I have looked at how other people have attempted it like http://introcs.cs.princeton.edu/java/31datatype/Tile.java[2] but have no idea why it works or if " Picture input = new Picture(args[0]);" that part is even part of java api.


It is not. Have you read the entire article that includes the source code for all involved classes?

they don't seem to work


What does this mean? What did you expect to happen, and what happened instead?



Woops the results of skim reading.

What I mean is, I have tried to create a tile but all it does is duplicate the file instead.

My code is similar to this: http://kalanir.blogspot.com.au/2010/02/how-to-split-image-into-chunks-java.html
But it doesn't output 16 files, all it does is copy two files ie. original -> original-tiled
+Pie Number of slices to send: Send
Well, we can't help with code we don't know. You may want to post relevant excerpts of it that demonstrate where it goes wrong.
+Pie Number of slices to send: Send
 

Ulf Dittmer wrote:Well, we can't help with code we don't know. You may want to post relevant excerpts of it that demonstrate where it goes wrong.






I just made a fresh start as the code from the previous site would keep creating new files and I had no idea to merge into one.
ANYWAYS, I created a new method to divide an image. I'm currently wondering
1. how I would seperate the image into 4 parts
2. whether I should create a new method which would gather all the details ie user entered data and parse them or have it in the same method.

Obviously #1 is the most important atm and I'm just stuck on it :S
+Pie Number of slices to send: Send
What exactly are you stuck on - where's the difficulty in creating 4 sub-images instead of one?
+Pie Number of slices to send: Send
 

Ulf Dittmer wrote:What exactly are you stuck on - where's the difficulty in creating 4 sub-images instead of one?


Everything.
I'm very new to Java, reading over tutorials over and over again but I have no clue how to properly work the Graphics2D / ImageIO functions hence asking for advice.
+Pie Number of slices to send: Send
 

kada kanz wrote:I'm very new to Java, reading over tutorials over and over again but I have no clue how to properly work the Graphics2D / ImageIO functions hence asking for advice.


Could I suggest then that this may be a bit beyond you at this time? Doesn't mean that it always will be, but graphics and images are not simple things to deal with. I know I'd be checking out the tutorials if I was trying to do something like it.

And in the meantime there are plenty of other things to try out.

Winston
+Pie Number of slices to send: Send
 

Everything


No, it's not that bad. In your first post you had essentially everything you need, except that you're cutting a section from somewhere in the middle of the image - which isn't too helpful if you want to create tiles. I've adapted it a bit to extract the top left quarter of an image:

It expects as parameter the name of a file ImageIO can read -like JPEG, PNG, GIF, BMP, TIFF- and creates a PNG as output. Now, can you extend that to create the 3 missing quarter images (top right, lower left and lower right)?
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2454 times.
Similar Threads
Image Resizing algorithm using Graphics2D java object not working on webServer.
Most efficient way to use a spritesheet?
What should a 2d tile-based map basically have???
Sending an image on network..
Why does a char value also have an integer value?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:01:09.