• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tiling an image  RSS feed

 
kada kanz
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
kada kanz
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kada kanz
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly are you stuck on - where's the difficulty in creating 4 sub-images instead of one?
 
kada kanz
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!