6 Replies - 835 Views - Last Post: 24 October 2010 - 07:43 PM Rate Topic: -----

#1 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 438
  • Joined: 15-May 08

[SOLVED] graphics draw image help

Posted 24 October 2010 - 03:58 PM

Hi guys.
i have an buffered image and i want to draw only a small peice of the image not the whole thing.

So i used.

g.drawImage(myImage,0, 0, 32, 32,null);


i looked at the Java Doc and found out that im scaleing my image.

Does anyone know how i would just take the first 32x32 pixels of my image?

This post has been edited by giuseppe105: 24 October 2010 - 07:59 PM

Is This A Good Question/Topic? 0
  • +

Replies To: [SOLVED] graphics draw image help

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8030
  • View blog
  • Posts: 31,164
  • Joined: 06-March 08

Re: [SOLVED] graphics draw image help

Posted 24 October 2010 - 04:45 PM

Better to get a "subImage" of your Image first

http://download.orac...getSubimage(int, int, int, int)
Was This Post Helpful? 1
  • +
  • -

#3 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 438
  • Joined: 15-May 08

Re: [SOLVED] graphics draw image help

Posted 24 October 2010 - 05:01 PM

k so i did this

this is my real code now. not an example.

tileSize = 32
x = 3
y = 1

for(int a = 0; a < x; a++)
		{
			for(int b = 0; b < y; b++)
			{
				tileSet[a][b] = new TileSet();
				g.drawImage(tileSetImage.getSubimage(a * tileSize, b * tileSize, (a * tileSize) + tileSize , (b * tileSize) + tileSize), 0, 0, null);
				tileSet[a][b].setTileImage(tileBuffer);
			}
		}


and im getting an error

java.awt.image.RasterFormatException: (x + width) is outside of Raster

This post has been edited by giuseppe105: 24 October 2010 - 05:07 PM

Was This Post Helpful? 0
  • +
  • -

#4 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 438
  • Joined: 15-May 08

Re: [SOLVED] graphics draw image help

Posted 24 October 2010 - 05:31 PM

could the problem be that its taking a point

(32,0) and trying to fit it in a image that's only a size of (32,32)
Was This Post Helpful? 0
  • +
  • -

#5 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 438
  • Joined: 15-May 08

Re: [SOLVED] graphics draw image help

Posted 24 October 2010 - 07:08 PM

well i think i figured out what i was doing wrong.

tnx for your help PBL i found 2 ways to do what i wanted today.

this method
public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)


is the same as
public abstract boolean drawImage(public BufferedImage getSubimage(int x, int y, int w, int h),int x, int y, ImageObserver observer)


that's so depressing... after the 2 hours i spent trying to fix the problem with my app i fixed working code...

This post has been edited by giuseppe105: 24 October 2010 - 07:24 PM

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8030
  • View blog
  • Posts: 31,164
  • Joined: 06-March 08

Re: [SOLVED] graphics draw image help

Posted 24 October 2010 - 07:32 PM

View Postgiuseppe105, on 24 October 2010 - 08:08 PM, said:

that's so depressing... after the 2 hours i spent trying to fix the problem with my app i fixed working code...

and won't be the last time son if you think to pursue in the IT business :^:
Was This Post Helpful? 0
  • +
  • -

#7 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 438
  • Joined: 15-May 08

Re: [SOLVED] graphics draw image help

Posted 24 October 2010 - 07:43 PM

I will just have to learn.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1