C
Chris Rehm
I have some code (included below), which to me looks exactly like the
code I've used elsewhere that works, but the image doesn't print. I just
don't get it.
I have a Rectangle r which is my current bounds rectangle. I want to
scale my image so that it will take up 100 % width and have a
proportional height. So, I figure out how many dots high it will be once
scaled and that is a float called ish.
I put in a few debug prints to check values, and they are coming out
accurate. I get the right height and width from the image
(logolineImage). The image has been loaded long before.
I've tried it without scaling, and without translate, and with just
plain default AffineTransform.
I draw a stroke around the border, and I write some text, all right
before I get to this point. All the other stuff shows up no problem.
AffineTransform imageAT = new AffineTransform();
float ish =
(float) (r.getHeight()
* ((float) logolineImage.getHeight(null)
/ (float) logolineImage.getWidth(null)));
System.out.println("ish " + ish);
System.out.println("image h " + logolineImage.getHeight(null));
System.out.println("image w " + logolineImage.getWidth(null));
System.out.println("r w " + r.getWidth());
System.out.println("r h " + r.getHeight());
imageAT.translate(0., r.getHeight() - ish);
imageAT.scale(
r.getWidth() / (float)logolineImage.getWidth(null),
ish / (float)logolineImage.getHeight(null));
g2.drawImage(logolineImage, imageAT, null);
--
Chris Rehm
(e-mail address removed)
Thou shalt not avenge, nor bear any grudge against the children of thy
people, but shalt love thy neighbour as thyself. [Lev. 19:18]
code I've used elsewhere that works, but the image doesn't print. I just
don't get it.
I have a Rectangle r which is my current bounds rectangle. I want to
scale my image so that it will take up 100 % width and have a
proportional height. So, I figure out how many dots high it will be once
scaled and that is a float called ish.
I put in a few debug prints to check values, and they are coming out
accurate. I get the right height and width from the image
(logolineImage). The image has been loaded long before.
I've tried it without scaling, and without translate, and with just
plain default AffineTransform.
I draw a stroke around the border, and I write some text, all right
before I get to this point. All the other stuff shows up no problem.
AffineTransform imageAT = new AffineTransform();
float ish =
(float) (r.getHeight()
* ((float) logolineImage.getHeight(null)
/ (float) logolineImage.getWidth(null)));
System.out.println("ish " + ish);
System.out.println("image h " + logolineImage.getHeight(null));
System.out.println("image w " + logolineImage.getWidth(null));
System.out.println("r w " + r.getWidth());
System.out.println("r h " + r.getHeight());
imageAT.translate(0., r.getHeight() - ish);
imageAT.scale(
r.getWidth() / (float)logolineImage.getWidth(null),
ish / (float)logolineImage.getHeight(null));
g2.drawImage(logolineImage, imageAT, null);
--
Chris Rehm
(e-mail address removed)
Thou shalt not avenge, nor bear any grudge against the children of thy
people, but shalt love thy neighbour as thyself. [Lev. 19:18]