• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Copy area in image into ArrayList for texturepack code

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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   .
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic