• Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy area in image into ArrayList for texturepack code  RSS feed

 
Artem Korneenko
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone. I have a problem.

I need to create some sort of texturepack for my game, here is all, that this code is need to do:

- On input we have a 512x512 .png image.
- Programm will need to copy a small region from that image and translate it to ArrayList.

- Next, i will make two loops to "scan" all image.


The problem is:

I really dont know, how to copy a part of image immediately from file (without render it to paintbox).



P.S. I'm a Russian guy, who tried to google normally, but couldn't find anything. Hope i have enough knowledge in english in order to talk to you  .
 
Norm Radder
Ranch Foreman
Posts: 2238
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to copy a part of image immediately from file

I don't know if java has a method to do that. 
If the image is read into a BufferedImage, the BufferedImage class has methods that would get a sub image from it into another BufferedImage object that could be put into an ArrayList.
 
Piet Souris
Rancher
Posts: 1943
66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating these subimages directly from a png file is not easy, given the complex file format.

So indeed, read your image into a BufferedImame (letting the java library do all of that hard stuff), and create your subimages by using a suitable method.

Depending on your needs, it may be wise to create a subclass of BufferedImage, that also contains, say, the index of the subimage and maybe the pixel coordinates of the top left pixel. That will make it easy to see what part of the original a subimage is. You can then store these into your List.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!