Re: [JAVA2D] Print BufferedImage Externally Generated

2008-12-29 Thread java2d
I too had the same problem. I was using an example app from the JOGL group that 
Chris Campbell mentioned to me and the crashing caused me to give up on being 
too creative with JOGL. the java gaming froum thought I was crazy to use that 
option you speak of since it was too unstable and they were right!

Chris did warn me about the app being experimental and to me the major issue 
was the one mentioned in this thread using that option. Problem is the demo 
required it.

Good Luck. Glad to hear someone is talking about it.

-Tony
[Message sent by forum member 'tdanecito' (tdanecito)]

http://forums.java.net/jive/thread.jspa?messageID=323556

===
To unsubscribe, send email to lists...@java.sun.com and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
lists...@java.sun.com and include in the body of the message help.


Re: [JAVA2D] Print BufferedImage Externally Generated

2008-12-22 Thread java2d
Thanks for all of your help everyone!
[Message sent by forum member 'wtrpirate' (wtrpirate)]

http://forums.java.net/jive/thread.jspa?messageID=323010

===
To unsubscribe, send email to lists...@java.sun.com and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
lists...@java.sun.com and include in the body of the message help.


Re: [JAVA2D] Print BufferedImage Externally Generated

2008-12-02 Thread Jim Graham
Phil already talked about why you are having resolution problems, but I 
wanted to point out a mistake in your code that was causing some of the 
operations to be lost.


[EMAIL PROTECTED] wrote:

Hi, I'm trying to build up a BufferedImage using its Graphics component, and 
then print that image using a Printable.  The problem is that some of my 
operations on the graphics component seem to be lost, and when I print the 
image, a lot of it is clipped off around the borders.  The code below shows the 
gist of what I'm doing.

// this method is in class A
foo(String text, Font font, B b, int x, int y) {
  Graphics2D g2d = (Graphics2D) image.getGraphics();
  g2d.setColor(Color.black);  // this color gets lost when bar is called
  g2d.setFont(font); // this font gets lost when bar is called
  b.bar(text, x, y);


In this code you never use g2d to draw anything.  You call getGraphics() 
on the image, which constructs a brand new Graphics object that is not 
shared with any other call to getGraphics() and then you set some 
attributes (color and font) on that graphics object and then you drop 
the reference on the floor so those attributes will never get used 
anywhere to draw anything.  The key things here are:


Image.getGraphics() always returns a new object that is never shared.

Graphics.setColor() sets the color for only that one graphics object, it 
has no effect on any other graphics object.  (The same is true with 
setFont()).



}

// this method is in class B
bar(String text, int x, int y) {
  Graphics2D g2d = (Graphics2D) image.getGraphics();


Here you obtain another brand new unshared graphics object from the 
image which is set to default values for all attributes.  In particular, 
this object will not have the color or font that you set in foo() 
because those attributes were set on a different graphics object.



  g2d.drawString(text, x, y); // this does not get lost when the image is 
printed
}

// this is the print method for the Printable, the image is passed to the 
Printable
print(Graphics g, PageFormat pf, int pageIndex) {
  if (pageIndex == 0) {
Graphics2D g2d = (Graphics2D)image.getGraphics();
g2d.translate(pf.getImageableX(), pf.getImageableY());


Here you obtain a 3rd graphics object from the image and you set its 
translation.  But, again, since you never draw anything with this g2d, 
the translation you set never gets used for anything.



((Graphics2D)graphics).drawImage(image, null, 0, 0);


Finally here you use some other graphics object (it isn't the one that 
was passed in to the print method - that one was called g - and it 
isn't the one that was obtained from the image - that one was called 
g2d, so I'm not sure where you are drawing this image to - it's being 
drawn to this mystery object called graphics that none of the code you 
included traces the creation of...?



return Printable.PAGE_EXISTS;
  } else {
return Printable.NO_SUCH_PAGE;
  }
}


If I hardcode the color and font in the bar method, then the text actually comes out at the 
printer, but if x  80 or x  500, it doesn't get printed; same if y  80 or y 
 600 (these are approximate, I'm just estimating based on what I printed and where it 
got cut off).  This leaves about a 1 inch margin around the printed text on the paper from 
the printer.  Ultimately, I want to generate a document image using j2d and send that to 
the printer.  Any help is greatly appreciated!


My comments above should help you realize why putting the color and font 
into the bar method is quite a different set of operations than trying 
to do it from the foo() method.  You cannot leave some attributes in a 
graphics object to be used by future graphics objects because each call 
to getGraphics() returns a brand new instance with preset defaults.


...jim

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] Print BufferedImage Externally Generated

2008-12-01 Thread java2d
Thanks for your help Phil.

 But
 I'm trying to build up a BufferedImage using its
  Graphics component, 
 nd then print that image using a Printable
 Why? As in I don't know why you aren't rendering
 directly to the printer ?

I have a builder for my non-print documents, but it seems that I can't apply 
the normal builder to a printer document because of the way java print services 
works.  If I were to apply the builder directly to the printer, it seems that I 
would have to somehow enter the print method in the builder and then have the 
director call the builder while it was in the print method, but that's not 
possible.  So instead, I'm trying to build an image and pass it to the 
printable.  But as you have pointed out, this is not a nice solution.  Any 
advice?


 The clipping is because the imageable area of the
 paper may be less than 
 the physical size of the paper.
 You need to get the imageable area from the
 PageFormat and then scale 
 your rendering (ie the final image) to fit.
 You can also control this by specifying the imageable
 area in the 
 PageFormat but you'll need to use the javax.print
 APIs to find out what is the hard liimit for the
 device
 See 
 http://java.sun.com/javase/6/docs/api/javax/print/attr
 ibute/standard/MediaPrintableArea.html
 
 But
 I'm trying to build up a BufferedImage using its
  Graphics component, 
 nd then print that image using a Printable
 Why? As in I don't know why you aren't rendering
 directly to the printer ?
 
 If you do what you are doing you will get blocky
 output, unless you 
 create a very large image and scale
 it to printer resolutions. Even then it means you
 won't get printer 
 fonts etc.
 
 So I suspect your approach is costing you in
 - output quality
 - memory used
 - performance
 
 -phil.
 
 [EMAIL PROTECTED] wrote:
  Hi, I'm trying to build up a BufferedImage using
 its Graphics component, and then print that image
 using a Printable.  The problem is that some of my
 operations on the graphics component seem to be lost,
 and when I print the image, a lot of it is clipped
 off around the borders.  The code below shows the
 gist of what I'm doing.
 
  // this method is in class A
  foo(String text, Font font, B b, int x, int y) {
Graphics2D g2d = (Graphics2D)
 image.getGraphics();
g2d.setColor(Color.black);  // this color gets
 lost when bar is called
g2d.setFont(font); // this font gets lost when
 bar is called
b.bar(text, x, y);
  }
 
  // this method is in class B
  bar(String text, int x, int y) {
Graphics2D g2d = (Graphics2D)
 image.getGraphics();
g2d.drawString(text, x, y); // this does not get
 lost when the image is printed
  }
 
  // this is the print method for the Printable, the
 image is passed to the Printable
  print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex == 0) {
  Graphics2D g2d =
 (Graphics2D)image.getGraphics();
  g2d.translate(pf.getImageableX(),
 pf.getImageableY());
  ((Graphics2D)graphics).drawImage(image, null,
 0, 0);
  return Printable.PAGE_EXISTS;
} else {
  return Printable.NO_SUCH_PAGE;
}
  }
 
 
  If I hardcode the color and font in the bar method,
 then the text actually comes out at the printer, but
 if x  80 or x  500, it doesn't get printed; same if
 y  80 or y  600 (these are approximate, I'm just
 estimating based on what I printed and where it got
 cut off).  This leaves about a 1 inch margin around
 the printed text on the paper from the printer.
 Ultimately, I want to generate a document image
 using j2d and send that to the printer.  Any help is
  greatly appreciated!
 
  Thanks in advance!
  [Message sent by forum member 'wtrpirate'
 (wtrpirate)]
 
 
 http://forums.java.net/jive/thread.jspa?messageID=3189
 09
 
 
 ==
 =
  To unsubscribe, send email to [EMAIL PROTECTED]
 and include in the body
  of the message signoff JAVA2D-INTEREST.  For
 general help, send email to
  [EMAIL PROTECTED] and include in the body of
 the message help.

 
 ==
 =
 To unsubscribe, send email to [EMAIL PROTECTED]
 and include in the body
 of the message signoff JAVA2D-INTEREST.  For
 general help, send email to
 [EMAIL PROTECTED] and include in the body of the
 message help.
[Message sent by forum member 'wtrpirate' (wtrpirate)]

http://forums.java.net/jive/thread.jspa?messageID=319384

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] Print BufferedImage Externally Generated

2008-12-01 Thread Phil Race

[EMAIL PROTECTED] wrote:

Thanks for your help Phil.


But

I'm trying to build up a BufferedImage using its
 Graphics component, 
nd then print that image using a Printable

Why? As in I don't know why you aren't rendering
directly to the printer ?


I have a builder for my non-print documents, but it seems that I can't 

 apply the normal builder to a printer document because of the way java print 
services works.
 If I were to apply the builder directly to the printer, it seems that I would 
have to somehow
  enter the print method in the builder and then have the director call the 
builder while it was
 in the print method, but that's not possible.  So instead, I'm trying to 
build an image and pass
 it to the printable.  But as you have pointed out, this is not a nice 
solution.  Any advice?

Consider that the rendering process first needs to obtain a Graphics instance, 
either
from BufferedImage.createGraphics() or the one passed in to Printable.print(..).
I cannot see why your builder should know or care what the origin is, nor do 
I see
why you can't call your builder's paint method from print().

-phil.

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] Print BufferedImage Externally Generated

2008-11-26 Thread Phil Race
The clipping is because the imageable area of the paper may be less than 
the physical size of the paper.
You need to get the imageable area from the PageFormat and then scale 
your rendering (ie the final image) to fit.
You can also control this by specifying the imageable area in the 
PageFormat but you'll need to use the javax.print

APIs to find out what is the hard liimit for the device
See 
http://java.sun.com/javase/6/docs/api/javax/print/attribute/standard/MediaPrintableArea.html


But
I'm trying to build up a BufferedImage using its Graphics component, 
and then print that image using a Printable

Why? As in I don't know why you aren't rendering directly to the printer ?

If you do what you are doing you will get blocky output, unless you 
create a very large image and scale
it to printer resolutions. Even then it means you won't get printer 
fonts etc.


So I suspect your approach is costing you in
- output quality
- memory used
- performance

-phil.

[EMAIL PROTECTED] wrote:

Hi, I'm trying to build up a BufferedImage using its Graphics component, and 
then print that image using a Printable.  The problem is that some of my 
operations on the graphics component seem to be lost, and when I print the 
image, a lot of it is clipped off around the borders.  The code below shows the 
gist of what I'm doing.

// this method is in class A
foo(String text, Font font, B b, int x, int y) {
  Graphics2D g2d = (Graphics2D) image.getGraphics();
  g2d.setColor(Color.black);  // this color gets lost when bar is called
  g2d.setFont(font); // this font gets lost when bar is called
  b.bar(text, x, y);
}

// this method is in class B
bar(String text, int x, int y) {
  Graphics2D g2d = (Graphics2D) image.getGraphics();
  g2d.drawString(text, x, y); // this does not get lost when the image is 
printed
}

// this is the print method for the Printable, the image is passed to the 
Printable
print(Graphics g, PageFormat pf, int pageIndex) {
  if (pageIndex == 0) {
Graphics2D g2d = (Graphics2D)image.getGraphics();
g2d.translate(pf.getImageableX(), pf.getImageableY());
((Graphics2D)graphics).drawImage(image, null, 0, 0);
return Printable.PAGE_EXISTS;
  } else {
return Printable.NO_SUCH_PAGE;
  }
}


If I hardcode the color and font in the bar method, then the text actually comes out at the 
printer, but if x  80 or x  500, it doesn't get printed; same if y  80 or y 
 600 (these are approximate, I'm just estimating based on what I printed and where it 
got cut off).  This leaves about a 1 inch margin around the printed text on the paper from 
the printer.  Ultimately, I want to generate a document image using j2d and send that to 
the printer.  Any help is greatly appreciated!

Thanks in advance!
[Message sent by forum member 'wtrpirate' (wtrpirate)]

http://forums.java.net/jive/thread.jspa?messageID=318909

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.
  


===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.