Re: [JAVA2D] sun.java2d.Disposer questions (possible leak)

2009-03-15 Thread java2d
I am experiencing the same problem (environment: tomcat). I choose to 
initialize Java2D early during boot of the application server instead having a 
memory later when it is being initialized by an app. This class is called as a 
wrapper for the original tomcat bootstrap class. 

This is only a workaround, I hope the two bugs that have been filed already 
will be solved soon.

public class PlusBoot {

  public static void main (String[] args) {
ImageIO.setUseCache(false);
// Configuration.getConfiguration();
Bootstrap.main(args);
  }

}
[Message sent by forum member 'ahus1' (ahus1)]

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

===
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] is it possible?

2008-07-10 Thread java2d
Hi thanks for answer...

  but i want to Draw it actually i have made custom UI for 
JTabbedPane from Romain Buy's examples, i have made small changes in it here 
is code,
following are 2 classes TabbedPane and AquaBarTabbedPaneUI.
The (String) title will display on top right on TabbedPane...

Please use this code and tell me necessary changes  
Thank you 
Code...1
TabbedPane.java
import java.awt.Color;
import javax.swing.JTabbedPane;

/**
 *
 * @author rty
 */
public class TabbedPane extends JTabbedPane{

private AquaBarTabbedPaneUI atpu = new AquaBarTabbedPaneUI();

private void init(){
setUI(atpu);
}

public Color getTitleColor() {
return atpu.getTitleColor();
}

public void setTitleColor(Color titleColor) {
atpu.setTitleColor(titleColor);
}

public TabbedPane(int tabPlacement, int tabLayoutPolicy) {
super(tabPlacement, tabLayoutPolicy);
init();
}

public TabbedPane(int tabPlacement) {
super(tabPlacement);
init();
}

public TabbedPane() {
init();
}


public void setTitle(String title) {
atpu.setTitle( title);
}

public String getTitle(){
return atpu.getTitle();
}


Code...2
AquaBarTabbedPaneUI .java

public class AquaBarTabbedPaneUI extends BasicTabbedPaneUI {

private static final Insets NO_INSETS = new Insets(0, 0, 0, 0);
private ColorSet selectedColorSet;
private ColorSet defaultColorSet;
private ColorSet hoverColorSet;
private boolean contentTopBorderDrawn = true;
private Color lineColor = new Color(158, 158, 158);
private Color dividerColor = new Color(200, 200, 200);
private Insets contentInsets = new Insets(10, 10, 10, 10);
private int lastRollOverTab = -1;
private String title = new String();
public static ComponentUI createUI(JComponent c) {
return new AquaBarTabbedPaneUI();
}
private Color titleColor = Color.BLACK;

public Color getTitleColor() {
return titleColor;
}

public void setTitleColor(Color titleColor) {
this.titleColor = titleColor;
Rectangle tabsRect = new Rectangle(0, 0, tabPane.getWidth(), 20);
tabPane.repaint(tabsRect);
}


public String getTitle(){
return title;
}

public void setTitle(String t){
title = t;
 Rectangle tabsRect = new Rectangle(0, 0, tabPane.getWidth(), 20);
 tabPane.repaint(tabsRect);
}

public AquaBarTabbedPaneUI() {

selectedColorSet = new ColorSet();
selectedColorSet.topGradColor1 = new Color(233, 237, 248);
selectedColorSet.topGradColor2 = new Color(158, 199, 240);

selectedColorSet.bottomGradColor1 = new Color(112, 173, 239);
selectedColorSet.bottomGradColor2 = new Color(183, 244, 253);

defaultColorSet = new ColorSet();
defaultColorSet.topGradColor1 = new Color(253, 253, 253);
defaultColorSet.topGradColor2 = new Color(237, 237, 237);

defaultColorSet.bottomGradColor1 = new Color(222, 222, 222);
defaultColorSet.bottomGradColor2 = new Color(255, 255, 255);

hoverColorSet = new ColorSet();
hoverColorSet.topGradColor1 = new Color(244, 244, 244);
hoverColorSet.topGradColor2 = new Color(223, 223, 223);

hoverColorSet.bottomGradColor1 = new Color(211, 211, 211);
hoverColorSet.bottomGradColor2 = new Color(235, 235, 235);

maxTabHeight = 20;

setContentInsets(0);
}

public void setContentTopBorderDrawn(boolean b) {
contentTopBorderDrawn = b;
}

public void setContentInsets(Insets i) {
contentInsets = i;
}

public void setContentInsets(int i) {
contentInsets = new Insets(i, i, i, i);
}

public int getTabRunCount(JTabbedPane pane) {
return pane.getTabCount();
}
 
protected void installDefaults() {
super.installDefaults();

RollOverListener l = new RollOverListener();
tabPane.addMouseListener(l);
tabPane.addMouseMotionListener(l);

tabAreaInsets = NO_INSETS;
tabInsets = new Insets(0, 0, 0, 1);
}
/*
protected boolean scrollableTabLayoutEnabled() {
return false;
}
*/
protected Insets getContentBorderInsets(int tabPlacement) {
return contentInsets;
}

protected int calculateTabHeight(int tabPlacement, int tabIndex,
int fontHeight) {
return 21;
}

protected int calculateTabWidth(int tabPlacement, int tabIndex,
FontMetrics metrics) {
int w = super.calculateTabWidth(tabPlacement, tabIndex, metrics);
int wid = metrics.charWidth('M');
w += wid * 2;
return w;
}

protected int calculateMaxTabHeight(int tabPlacement) {
return 21;
}

protected void paintTabArea(Graphics g, int tabPlacement, int 
selectedIndex) {
Graphics2D g2d 

Re: [JAVA2D] is it possible?

2008-07-10 Thread Harald Kuhr

On 10. juli. 2008, at 11.18, [EMAIL PROTECTED] wrote:


but i want to Draw it


Try something like:

@Override
protected void paintComponent(Graphics g) {
...

String html = ...;

JLabel label = new JLabel(html);
label.setBounds(getBounds());
label.setVisible(true);
label.paint(g);

   ...
}

Feels a little hackish, but should work...


.k

===
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] is it possible?

2008-07-09 Thread Dmitri Trembovetski

[EMAIL PROTECTED] wrote:

Hello...

Drawing HTML code in Panel ??
i.g.
String s = htmlH1Hello../H1/html;


  This should be possible:
  add(new JLabel(s));

  Dmitri



g2d.drawString(s,x,y);

OR any other way?? to draw HTML in Panel using Graphics2D...  :D
[Message sent by forum member 'abc3d' (abc3d)]

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

===
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.


Re: [JAVA2D] sun.java2d.Disposer questions (possible leak)

2007-01-26 Thread java2d
Is there any chance of getting a fix for this bug in the somewhat near future? 
:-)
[Message sent by forum member 'plethora' (plethora)]

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

===
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] sun.java2d.Disposer questions (possible leak)

2007-01-26 Thread Dmitri Trembovetski

  I've filed this bug a while ago:
6489540: The Disposer thread could cause memory leaks in user
applications
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6489540

  Unfortunately without some changes in another area
  it can not be fully fixed, so I filed this bug:
6501120: (thread) Existing constructors lead to pinnned copies of
inheritable thread locals
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6501120

  Fix for this bug is currently under review. Once it's
  done, I will be able to fix the disposer.

  Thanks,
Dmitri
  Java2D Team

[EMAIL PROTECTED] wrote:

Is there any chance of getting a fix for this bug in the somewhat near future? 
:-)
[Message sent by forum member 'plethora' (plethora)]

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

===
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.


Re: [JAVA2D] sun.java2d.Disposer questions (possible leak)

2007-01-26 Thread java2d
Dmitri, thanks for the detailed update.
[Message sent by forum member 'plethora' (plethora)]

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

===
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] sun.java2d.Disposer questions (possible leak)

2006-11-03 Thread java2d
Dmitri,

Thanks for the quick response and for entering the bug.
I will take a look once it becomes visible.

It might be a good idea to inspect all active (threaded) run-until-JVM-shutdown 
subsystems for contextClassLoader reference leaks.

Regards,
Taras
[Message sent by forum member 'plethora' (plethora)]

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

===
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] sun.java2d.Disposer questions (possible leak)

2006-11-02 Thread java2d
OK, I've filed a bug (will appear on bug parade in a day):
  6489540: The Disposer thread could cause memory leaks in user applications

I've also found out that there's no way to address the first
problem about inheritable thread local storage (see bug's evaluation).

But the second one - with context classloader - will
be fixed.

Dmitri
[Message sent by forum member 'trembovetski' (trembovetski)]

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

===
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] sun.java2d.Disposer questions (possible leak)

2006-06-27 Thread Dmitri Trembovetski
On Mon, Jun 26, 2006 at 10:47:29PM -0700, [EMAIL PROTECTED] wrote:
  Sure, let's say I manageg to remove all the inheritableThreadLocals.
 
  The next issue is the contextClassLoader that is propagated to the Java2D 
  Disposer Thread. Which, of course, is exactly the ClassLoader I'd like to 
  unload (the one with 1GB+ data referenced).
 
  Any idea how to do that?

  Unfortunately I don't know. I'll ask around.

  Thanks,
Dmitri


 [Message sent by forum member 'plethora' (plethora)]
 
  http://forums.java.net/jive/thread.jspa?messageID=127369
 
  ===
  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.


Re: [JAVA2D] sun.java2d.Disposer questions (possible leak)

2006-06-27 Thread Dmitri Trembovetski
  But before I start asking I need to understand
  more about this.

  Do you set your own classloader, or is it the default
  one?

  Better yet, is there any way you could create a small
  test case illustrating the problem?

  Thanks,
Dmitri

On Tue, Jun 27, 2006 at 06:18:19AM -0700, Dmitri Trembovetski wrote:
  On Mon, Jun 26, 2006 at 10:47:29PM -0700, [EMAIL PROTECTED] wrote:
Sure, let's say I manageg to remove all the inheritableThreadLocals.
   
The next issue is the contextClassLoader that is propagated to the Java2D 
  Disposer Thread. Which, of course, is exactly the ClassLoader I'd like to 
  unload (the one with 1GB+ data referenced).
   
Any idea how to do that?
 
Unfortunately I don't know. I'll ask around.
 
Thanks,
  Dmitri
 
 
   [Message sent by forum member 'plethora' (plethora)]
   
http://forums.java.net/jive/thread.jspa?messageID=127369
   

  ===
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.

===
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] sun.java2d.Disposer questions (possible leak)

2006-06-26 Thread Dmitri Trembovetski
  Hi,

On Sun, Jun 25, 2006 at 01:02:35PM -0700, [EMAIL PROTECTED] wrote:
  Hi Dmitri,
 
  Is Mustang b89 recent enough to test?

  Yes, that should do it.

  Out of curiosity, what was changed wrt the Disposer in Mustang? Is the 
  disposer thread initialized on JVM startup?

  The change is covered under this bug id:
6321642: Disposer Thread must be a member of system app context
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6321642

  BTW, the application is a J2EE web app, sometimes serving some graphs with 
  historical data. The InheritableThreadLocal comes from the Spring framework 
  DispatcherServlet (LocaleContextHolder).
 
  Is there any workaround for this leak on JDK 1.5.0 (_07)?

  Well, we're not yet sure if it was fixed in mustang yet.
  If we find that the fix above does help, we could backport it
  to the next 5.0 update release.

  One way to work around it would be to do some graphics operations
  to a scratch buffer early on a separate thread so that the Disposer
  gets initialized early.

  Thanks,
Dmitri

===
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] sun.java2d.Disposer questions (possible leak)

2006-06-26 Thread java2d
The leak is still there in Mustang b89.
[Message sent by forum member 'plethora' (plethora)]

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

===
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] sun.java2d.Disposer questions (possible leak)

2006-06-26 Thread Dmitri Trembovetski
  Could you try the workaround I've suggested?
  (do some java2d activity  - in particular, create a BufferedImage and
  render to it - on a thread created either
  prior to creating and setting the InheritableThreadLocalStorage
  or started from a separate thread).

  I'll think on what we can do to avoid running into this in the
  meantime.

  Thanks,
   Dmitri


On Mon, Jun 26, 2006 at 06:00:09AM -0700, [EMAIL PROTECTED] wrote:
  The leak is still there in Mustang b89.
  [Message sent by forum member 'plethora' (plethora)]
 
  http://forums.java.net/jive/thread.jspa?messageID=126968
 
  ===
  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.


Re: [JAVA2D] sun.java2d.Disposer questions (possible leak)

2006-06-26 Thread Dmitri Trembovetski
  Hi,

On Mon, Jun 26, 2006 at 07:22:35AM -0700, Dmitri Trembovetski wrote:
 
Could you try the workaround I've suggested?
(do some java2d activity  - in particular, create a BufferedImage and
render to it - on a thread created either
prior to creating and setting the InheritableThreadLocalStorage
or started from a separate thread).
 
I'll think on what we can do to avoid running into this in the
meantime.

  I don't think we could a whole lot here. The Disposer thread
  is created in the static initializer of the Disposer class -
  we don't have any control over which thread creates it.

  Note that pretty much the same issue could happen with,
  say, EventDispatchThread, or any other thread created
  by the JDK in similar fashion (may be even finalizer
  thread?). So perhaps you should reconsider which thread
  have their storage inheritable.

  We could ask for a new API such that a thread would refuse
  the inheritance of local storage from a parent.

  You could probably try to work around this by overriding
  InheritableThreadLocal.childValue() and returning null if
  you're about to give away the ThreadLocal to some unkown thread.
  Not sure how you would distinguish from unknown and
  known threads, though - I'm assuming childValue() is called
  on the parent thread. You could do something like this:
...
creatingThread = true;
myThread = new Thread();
thread.start();

  In your thread local:
  Object InheritableThreadLocal.childValue(Object parentValue) {
if (!creatingThread) return null;
// return your regular local object...
creatingThrad = false;
return parentValue;
  }

  It ain't pretty, but it might work.

  Thanks,
Dmitri

 
Thanks,
 Dmitri
 
 
  On Mon, Jun 26, 2006 at 06:00:09AM -0700, [EMAIL PROTECTED] wrote:
The leak is still there in Mustang b89.
[Message sent by forum member 'plethora' (plethora)]
   
http://forums.java.net/jive/thread.jspa?messageID=126968
   

  ===
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.


Re: [JAVA2D] sun.java2d.Disposer questions (possible leak)

2006-06-26 Thread java2d
Sure, let's say I manageg to remove all the inheritableThreadLocals.

The next issue is the contextClassLoader that is propagated to the Java2D 
Disposer Thread. Which, of course, is exactly the ClassLoader I'd like to 
unload (the one with 1GB+ data referenced).

Any idea how to do that?
[Message sent by forum member 'plethora' (plethora)]

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

===
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] sun.java2d.Disposer questions (possible leak)

2006-06-25 Thread java2d
Hi Dmitri,

Is Mustang b89 recent enough to test?

Out of curiosity, what was changed wrt the Disposer in Mustang? Is the disposer 
thread initialized on JVM startup?

BTW, the application is a J2EE web app, sometimes serving some graphs with 
historical data. The InheritableThreadLocal comes from the Spring framework 
DispatcherServlet (LocaleContextHolder).

Is there any workaround for this leak on JDK 1.5.0 (_07)?
[Message sent by forum member 'plethora' (plethora)]

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

===
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] sun.java2d.Disposer questions (possible leak)

2006-06-12 Thread Dmitri Trembovetski
  Hello,

On Fri, Jun 09, 2006 at 01:52:32PM -0700, [EMAIL PROTECTED] wrote:
  First, is there a good description available on how the sun.java2d.Disposer 
  class works in Java 1.5.0?

  There isn't such a description. Disoser is an internal mechanism
  for disposing of graphics-related resources and is not public.

  Second, I think I've found a possible reference leak.
 
  1) A console-only application is started.
  2) After 10 minutes of running, a thread dump does NOT show any Java2D 
  Disposer thread.
  3) After 20 minutes of running, a background image is created using Java2D, 
  and sent over the network. (The image is never shown on screen, the app is 
  still running in console mode)
  4) After (3) above, a new thread can be seen in the thread dump (the 
  sun.java2d.Disposer thread).

  All this seem to work as expected.

  Now, the original thread that started the offline rendering had a couple of 
  InheritableThreadLocals set. I don't know how/where the disposer thread is 
  created, but it appears that it (as you would guess) inherits the 
  InteritableThreadLocals of the thread that caused Java2D to be (lazily?) 
  initialized.
 
  Of course, one of the InheritableThreadLocals (indirectly) references a 
  ClassLoader that has 2GB of memory attached. Later in the application 
  lifecycle, this prevents garbage collection, and triggers a memory overflow 
  (OOM).
  [Message sent by forum member 'plethora' (plethora)]

  Could you please try your test on Mustang? http://mustang.dev.java.net .
  We've made some changes in mustang to the way the disposer thread is
  started which could have affected your problem.

  Thank you,
Dmitri
  Java2D Team


  http://forums.java.net/jive/thread.jspa?messageID=121561
 
  ===
  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.


Re: [JAVA2D] Is It possible to do Image Conversion without distortion...

2004-09-21 Thread Chris Campbell
Hi Palani,
Could you explain what you mean by distorted?  I ran your testcase
and it seems to work as expected.
BTW, your code that calculates the scale factors and whatnot could be
greatly simiplified.  Since you're just doing simple scaling, there's
no need to use AffineTransform.  Instead, you can simply use the
scaling drawImage() variant.  (We should probably write up an article
that demonstrates the best approaches for image scaling...)
Here's the simplified code:
public JPGImage(String srcFileName,String destFileName,
int thumbNailSize) throws Exception
{
// Read in original image to create thumbnail from
File inFile = new File(srcFileName);
BufferedImage bufferedImage = ImageIO.read(inFile);
// Calculate scale so image fits in a square area of
thumbNailSize
int imageWidth = bufferedImage.getWidth();
int imageHeight = bufferedImage.getHeight();
int scaledWidth, scaledHeight;
if (imageWidth  imageHeight) {
scaledWidth = thumbNailSize;
scaledHeight =
(int)(thumbNailSize * (((double)imageHeight) /
imageWidth));
} else {
scaledWidth =
(int)(thumbNailSize * (((double)imageWidth) /
imageHeight));
scaledHeight = thumbNailSize;
}
BufferedImage scaledBufferedImage =
new BufferedImage(scaledWidth, scaledHeight,
  BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = scaledBufferedImage.createGraphics();
g2d.drawImage(bufferedImage, 0, 0, scaledWidth, scaledHeight,
null);
g2d.dispose();
// Now write out scaled image to file
ImageIO.write(scaledBufferedImage,JPG,new File(destFileName));
}
Thanks,
Chris
On Sep 19, 2004, at 11:51 PM, Palani Murugan wrote:
Below is the code for Image Conversion for JPG format.
This code works fine but it gives distorted Image.
Is It possible to do Image Conversion without distortion ???
Note:
This Program takes 3 command line argument...
***

java JPGImage source file Name Destination file Name size of
Image
***

***

import java.io.*;
import javax.imageio.*;
import java.awt.image.*;
import java.awt.geom.*;
public class JPGImage
{
 public JPGImage(String srcFileName,String destFileName,int
thumbNailSize) throws Exception
 {
 // Read in original image to create thumbnail from
 File inFile = new File(srcFileName);
 BufferedImage bufferedImage = ImageIO.read(inFile);
 bufferedImage.flush();
 // Calculate scale so image fits in a square area of thumbNailSize
 int imageWidth = bufferedImage.getWidth();
 int imageHeight = bufferedImage.getHeight();
 int componentWidth = thumbNailSize;
 int componentHeight = thumbNailSize;
 double scale = -1;
 if ( imageWidth == componentWidth  imageHeight ==
componentHeight){
  scale = 1;
 }
 else if ( imageWidth = componentWidth  imageHeight =
componentHeight)
 {
  double heightScale = ((double)componentWidth) / ((double)
imageWidth);
  double widthScale = ((double)componentHeight) / ((double)
imageHeight);
  if ( heightScale  widthScale ) scale = heightScale;
  else scale = widthScale;
 }
 else if ( imageWidth  componentWidth  imageHeight =
componentHeight)
 {
  double heightScale = ((double)componentWidth) / ((double)
imageWidth);
  scale = heightScale;
 }
 else if ( imageWidth = componentWidth  imageHeight 
componentHeight)
 {
  double widthScale = ((double)componentHeight) / ((double)
imageHeight);
  scale = widthScale;
 }
 else
 {
  double heightScale = ((double)componentWidth) / ((double)
imageWidth);
  int scaledHeight = (int)(((double)imageHeight) *
heightScale);
  double widthScale = ((double)componentHeight) / ((double)
imageHeight);
  int scaledWidth = (int)(((double)imageWidth) * widthScale);
  if ( scaledWidth = componentWidth ) scale = widthScale;
  else scale = heightScale;
 }
 // Now create thumbnail
 AffineTransform affineTransform = AffineTransform.getScaleInstance
(scale,scale);
 AffineTransformOp affineTransformOp = new AffineTransformOp
(affineTransform,null);
 BufferedImage scaledBufferedImage = affineTransformOp.filter
(bufferedImage,null);
 int scaledWidth = scaledBufferedImage.getWidth();
 int scaledHeight = scaledBufferedImage.getHeight();
 int expectedWidth = (int)(imageWidth * scale);
 int expectedHeight = (int)(imageHeight * scale);
 if ( scaledWidth  expectedWidth || scaledHeight  expectedHeight )
 scaledBufferedImage = scaledBufferedImage.getSubimage
(0,0,expectedWidth,expectedHeight);
 // Now write out scaled image to file
 ImageIO.write(scaledBufferedImage,JPG,new File(destFileName));
}
 public static void main(String[] args)
 {
  if ( args.length  3 )
  {
   System.err.println(Usage: imageTest srcFile
DestFile size);