Re: Batch image compression problem. Help!



hkchris wrote:
> I am using Java to develop a web application that lets user to upload
> images
> to the web server, and the server will automatically resize and
> compress the
> images. It lets users to upload maximum 5 images at one time. The
> system
> works fine. But sometimes a very strange problem occurs. When the
> users
> upload the image, the images are able to be uploaded to the system
> successfully, but the system is hanged on the image compression stage.
> The
> system message returns that the uploaded images are under compression,
> but
> never ended, even one hour.
>
> I have checked the system log and find there is nothing mentioned in
> the log
> file. This problem doesn't happen regularly, but it does happen
> sometimes.
>
> Please kindly advise me what mistake I have made.
>
> Thanks,
> Chris
>
>
> Herebelow is the part of source code:
> ==============================================================
> /**
> * create small image.
> * @param oldImage,give a image to create small image.
> * @param newImage,the image you want to create.
> * @param maxWidth,the max width.
> * @param maxHeight, the max height.
> * @return the image's name.
> * @throws java.lang.Exception
> */
> public String createThumbnail(String srcImg,String objImg, int
> maxWidth,int maxHeight) throws Exception{
> try {
> EuwLog.EuwPrint("Begin Thumbnail"+objImg);
> ImageIcon ii = new ImageIcon(srcImg);
> Image i = ii.getImage();
> ii = null;
> Image temp = null;
> BufferedImage bufferedImage=null;
> int iWidth = i.getWidth(null);
> int iHeight = i.getHeight(null);
> double ratio = getRatio(iWidth,iHeight,maxWidth,maxHeight);
> iWidth = (int)(ratio*iWidth);
> iHeight = (int)(ratio*iHeight);
> if (ratio<1.0f){
> temp =
> i.getScaledInstance(iWidth,iHeight,Image.SCALE_AREA_AVERAGING);
> i.flush();
> i = null;
>
> temp = new ImageIcon(temp).getImage();
> // Create the buffered image.
> bufferedImage = new BufferedImage(iWidth, iHeight,
> BufferedImage.TYPE_INT_RGB);
>
> // Copy image to buffered image.
> Graphics g = bufferedImage.createGraphics();
> // Clear background and paint the image.
> g.setColor(Color.white);
> g.fillRect(0, 0, iWidth,iHeight);
> g.drawImage(temp, 0, 0, null);
> g.dispose();
> g = null;
>
> // sharpen
> float[] sharpenArray = { -0.125f, -0.125f, -0.125f, -0.125f,2,
> -0.125f, -0.125f, -0.125f, -0.125f };
> Kernel kernel = new Kernel(3, 3, sharpenArray);
> ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
> null);
> bufferedImage = cOp.filter(bufferedImage, null);
> cOp = null;
> kernel = null;
> /* write the jpeg to a file */
> //File file = new File(objImg);
> FileOutputStream out = new FileOutputStream(objImg);
> /* encodes image as a JPEG data stream */
> JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
> JPEGEncodeParam param =
> encoder.getDefaultJPEGEncodeParam(bufferedImage);
> // writeParam = new JPEGImageWriteParam(null);
> //
> writeParam.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
>
> //writeParam.setProgressiveMode(JPEGImageWriteParam.MODE_DEFAULT);
> param.setQuality(0.9f, true);
> encoder.setJPEGEncodeParam(param);
> encoder.encode(bufferedImage);
> param = null;
> encoder = null;
>
> temp.flush();
> temp = null;
>
> bufferedImage.flush();
> bufferedImage = null;
>
> out.close();
> out = null;
> EuwLog.EuwPrint("End Thumbnail"+objImg);

This question seems to have less to do with image processing and more
to do with how your platform works. (An image processing question would
be about the compression scheme itself, not a system-level problem in a
compression program.) Try in a Java or other newsgroup.

Cheers! --M

.



Relevant Pages

  • Re: Upload: Berios "Sinfonia" original LP transfer to digital 320k MP3
    ... Actually, the original transfer was made at 24bit/96kHz, but can only ... I +could+ have uploaded the files in lossless, ... suggestion, rather than upload all of the movements individually, why not put ... 650MB to a gigabyte of uploaded files (using lossless compression), ...
    (rec.music.classical.recordings)
  • Re: Batch image compression problem. Help!
    ... >images to the web server, and the server will automatically resize and ... It lets users to upload maximum 5 images at one ... >under compression, but never ended, even one hour. ... I noticed that you method throws "Exception". ...
    (comp.lang.java.help)
  • Batch image compression problem. Help!
    ... to the web server, and the server will automatically resize and compress the ... It lets users to upload maximum 5 images at one time. ... but the system is hanged on the image compression stage. ... public String createThumbnail(String srcImg,String objImg, int ...
    (comp.lang.java.programmer)
  • Batch image compression problem. Help!
    ... to the web server, and the server will automatically resize and compress the ... It lets users to upload maximum 5 images at one time. ... but the system is hanged on the image compression stage. ... public String createThumbnail(String srcImg,String objImg, int ...
    (comp.lang.java.help)
  • Batch image compression problem. Help!
    ... to the web server, and the server will automatically resize and ... It lets users to upload maximum 5 images at one time. ... but the system is hanged on the image compression stage. ... public String createThumbnail(String srcImg,String objImg, int ...
    (sci.image.processing)

Loading