You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by insom <da...@gmail.com> on 2008/08/18 17:32:25 UTC
Wicket Image -> Java Image
I'm printing text to an image before adding it to the page. Right now the
process goes like this:
final BufferedDynamicImageResource resource = new
BufferedDynamicImageResource();
java.awt.image.BufferedImage image;
image = ImageIO.read(new File("C:\\path\\to\\image.png"));
Graphics graphics = image.getGraphics();
graphics.drawString(user.getName(), 443, 215);
resource.setImage(image);
add(new Image("bothCardImage", resource));
In order to keep everything relative to the Wicket framework, I want to
replace
java.awt.image.BufferedImage image = ImageIO.read(new
File("C:\\path\\to\\image.png"));
Graphics graphics = image.getGraphics();
with
org.apache.wicket.markup.html.image.Image wicketImage;
wicketImage = new Image("img", new
ResourceReference(ImageAnchor.class, "image.png"));
Graphics graphics = wicketImage.getGraphics();
However, I can't figure out how to "getGraphics()" from a Wicket Image. Any
suggestions? Thanks much!
--
View this message in context: http://www.nabble.com/Wicket-Image--%3E-Java-Image-tp19034138p19034138.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket Image -> Java Image
Posted by insom <da...@gmail.com>.
Confused? Who, me? Okay, I confess, graphics are a gaping hole in my Java
knowledge. Here's the working solution I came up with in the end, using a
BufferedDynamicImageResource. I'll have to do some more figuring to see how
to do it with a RenderedDynamicImageResource.
BufferedDynamicImageResource resource = new
BufferedDynamicImageResource();
BufferedImage image;
try {
image = ImageIO.read(((WebApplication)
Application.get()).getServletContext().getResourceAsStream("/WEB-INF/classes/images/image.png"));
Graphics graphics = image.getGraphics();
graphics.drawString(user.getName(), 443, 215);
} catch (IOException ioe) {
// ...
}
resource.setImage(image);
add(new Image("bothCardImage", resource));
Al Maw wrote:
>
> Sounds to me like you're somewhat confused. ;-)
> Load the image from the classpath into a bufferedimage as you would
> outside of Wicket (Foo.class.getResourceAsStream() or whatever it is).
> Draw text, etc. on it as you see fit.
> Display it with Wicket if you want to via a BufferedDynamicImageResource.
>
> If you don't want the overhead of storing the image in the session,
> use a RenderedDynamicImageResource and load the classpath resource
> image in the render method.
>
> These things are always a trade-off between having to do the graphics
> drawing operations every time you render the page, and keeping the
> image hanging around which takes up space. Your choice.
>
> Regards,
>
> Al
>
>
--
View this message in context: http://www.nabble.com/Wicket-Image--%3E-Java-Image-tp19034138p19164891.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket Image -> Java Image
Posted by Al Maw <wi...@almaw.com>.
Sounds to me like you're somewhat confused. ;-)
Load the image from the classpath into a bufferedimage as you would
outside of Wicket (Foo.class.getResourceAsStream() or whatever it is).
Draw text, etc. on it as you see fit.
Display it with Wicket if you want to via a BufferedDynamicImageResource.
If you don't want the overhead of storing the image in the session,
use a RenderedDynamicImageResource and load the classpath resource
image in the render method.
These things are always a trade-off between having to do the graphics
drawing operations every time you render the page, and keeping the
image hanging around which takes up space. Your choice.
Regards,
Al
2008/8/22 insom <da...@gmail.com>:
>
> Sorry, it took me a bit to get back to this problem. Do you mean I can do
> this:
>
> org.apache.wicket.markup.html.image.Image wicketImage;
> wicketImage = new Image("img", new ResourceReference(ImageAnchor.class,
> "image.png"));
>
> RenderedDynamicImageResource wicketImageResource;
> wicketImageResource = new RenderedDynamicImageResource(1013,1276, "png")
> {
> protected boolean render(Graphics2D graphics) {
> graphics.drawString(user.getName(), 443, 215);
> return true;
> }
> };
> wicketImageResource.render(/* Somehow get wicketImage's Graphics
> attribute in here */);
>
> add(new Image("theImage", wicketImageResource));
>
> As you can tell, my difficulty is still in how I can grab the Image using
> the ResourceReference and then draw a String onto it. I hope this clarifies
> where I'm having trouble. Thanks again for your help.
>
>
> jwcarman wrote:
>>
>> You can use Graphics2D's drawImage() method can't you?
>>
>
> --
> View this message in context: http://www.nabble.com/Wicket-Image--%3E-Java-Image-tp19034138p19099200.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket Image -> Java Image
Posted by insom <da...@gmail.com>.
Sorry, it took me a bit to get back to this problem. Do you mean I can do
this:
org.apache.wicket.markup.html.image.Image wicketImage;
wicketImage = new Image("img", new ResourceReference(ImageAnchor.class,
"image.png"));
RenderedDynamicImageResource wicketImageResource;
wicketImageResource = new RenderedDynamicImageResource(1013,1276, "png")
{
protected boolean render(Graphics2D graphics) {
graphics.drawString(user.getName(), 443, 215);
return true;
}
};
wicketImageResource.render(/* Somehow get wicketImage's Graphics
attribute in here */);
add(new Image("theImage", wicketImageResource));
As you can tell, my difficulty is still in how I can grab the Image using
the ResourceReference and then draw a String onto it. I hope this clarifies
where I'm having trouble. Thanks again for your help.
jwcarman wrote:
>
> You can use Graphics2D's drawImage() method can't you?
>
--
View this message in context: http://www.nabble.com/Wicket-Image--%3E-Java-Image-tp19034138p19099200.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket Image -> Java Image
Posted by James Carman <ja...@carmanconsulting.com>.
You can use Graphics2D's drawImage() method can't you?
On Mon, Aug 18, 2008 at 11:53 AM, insom <da...@gmail.com> wrote:
>
>
> jwcarman wrote:
>>
>> Have you tried this:
>>
>> http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/markup/html/image/resource/RenderedDynamicImageResource.html
>>
>
> I hadn't tried it. Looking at it now, it appears to do the opposite of what
> I want. Its render(Graphics2D) function takes a Graphics input, but I'm
> looking for a way to get a Graphics as an output. However, I am by no means
> a Java graphics expert, so please tell me if I'm overlooking something that
> RenderedDynamicImageResource can do.
>
> Thanks again --
> --
> View this message in context: http://www.nabble.com/Wicket-Image--%3E-Java-Image-tp19034138p19034522.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket Image -> Java Image
Posted by insom <da...@gmail.com>.
jwcarman wrote:
>
> Have you tried this:
>
> http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/markup/html/image/resource/RenderedDynamicImageResource.html
>
I hadn't tried it. Looking at it now, it appears to do the opposite of what
I want. Its render(Graphics2D) function takes a Graphics input, but I'm
looking for a way to get a Graphics as an output. However, I am by no means
a Java graphics expert, so please tell me if I'm overlooking something that
RenderedDynamicImageResource can do.
Thanks again --
--
View this message in context: http://www.nabble.com/Wicket-Image--%3E-Java-Image-tp19034138p19034522.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket Image -> Java Image
Posted by James Carman <ja...@carmanconsulting.com>.
Have you tried this:
http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/markup/html/image/resource/RenderedDynamicImageResource.html
On Mon, Aug 18, 2008 at 11:32 AM, insom <da...@gmail.com> wrote:
>
> I'm printing text to an image before adding it to the page. Right now the
> process goes like this:
>
> final BufferedDynamicImageResource resource = new
> BufferedDynamicImageResource();
> java.awt.image.BufferedImage image;
> image = ImageIO.read(new File("C:\\path\\to\\image.png"));
> Graphics graphics = image.getGraphics();
> graphics.drawString(user.getName(), 443, 215);
> resource.setImage(image);
> add(new Image("bothCardImage", resource));
>
> In order to keep everything relative to the Wicket framework, I want to
> replace
>
> java.awt.image.BufferedImage image = ImageIO.read(new
> File("C:\\path\\to\\image.png"));
> Graphics graphics = image.getGraphics();
>
> with
>
> org.apache.wicket.markup.html.image.Image wicketImage;
> wicketImage = new Image("img", new
> ResourceReference(ImageAnchor.class, "image.png"));
> Graphics graphics = wicketImage.getGraphics();
>
> However, I can't figure out how to "getGraphics()" from a Wicket Image. Any
> suggestions? Thanks much!
> --
> View this message in context: http://www.nabble.com/Wicket-Image--%3E-Java-Image-tp19034138p19034138.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org