|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Scaling, Encoding, Loss of Qualityi have used scaling operations in the past,, all of which have mostly excellent quality if you store the file using filestore operation. perfectly happy with these.
however, i am currently working on storing the images in a db for reason we wont get into.... and these images need to be moved to a byte array. servlet served images on scaled on the fly. (i know dangerous memory problems) strange thing i cant seem to get to the bottom of. using the same scaling method i had previously used with the filestore operation that rendered excellent results is loosing a lot of quality. sample code first of the scale with filestore that works well.. then of scaling to the byte array.. double hRatio = ((double) edgeLength) / ((double) image.getHeight()); double wRatio = ((double) edgeLength) / ((double) image.getWidth()); double scale = Math.min(hRatio, wRatio); ParameterBlock scale_pb = new ParameterBlock(); scale_pb.addSource(image).add(scale).add(scale); RenderedImage image = JAI.create("SubsampleAverage", scale_pb, qualityHints) JPEGEncodeParam param = new JPEGEncodeParam(); param.setQuality(1.2F); ParameterBlock pb = new ParameterBlock(); pb.add("/tmp/test.jpg"+ ); pb.addSource(pum.writeRenderedImage()); pb.add("jpeg"); pb.add(param); RenderedOp op = JAI.create("filestore", pb); op.dispose(); ----------------- double hRatio = ((double) edgeLength) / ((double) image.getHeight()); double wRatio = ((double) edgeLength) / ((double) image.getWidth()); double scale = Math.min(hRatio, wRatio); ParameterBlock scale_pb = new ParameterBlock(); scale_pb.addSource(image).add(scale).add(scale); RenderedImage image = JAI.create("SubsampleAverage", scale_pb, qualityHints) ColorModel cm = image.getColorModel(); int width = image.getWidth(); int height = image.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable properties = new Hashtable(); String[] keys = image.getPropertyNames(); if (keys!=null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], image.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); image.copyData(raster); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ImageIO.write(result, format, baos); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } byte[] bytesOut = baos.toByteArray(); -------------------- bytesOut looks like crap... images here --> http://denniscg.com/20090506/filestored.jpg http://denniscg.com/20090506/withoutfilestore.jpg yes that is my beast... =) the question is what is the "filestore" operation doing that i am missing when going straight to the bytearray that would cause this loss of quality? any help from greater minds would be exponentially appreciated. [Message sent by forum member 'nathandennis' (nbd@...)] http://forums.java.net/jive/thread.jspa?messageID=367947 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: Scaling, Encoding, Loss of Qualityone more thing... when moving to a buffered image i have also tried for jpegs... etc.. with no real luck.
JPEGEncodeParam param = new JPEGEncodeParam(); param.setQuality(1.2F); ParameterBlock pb = new ParameterBlock(); pb.add(outputStream); pb.addSource(image); pb.add(type); pb.add(param); bufimage = JAI.create("encode", pb, hints).getAsBufferedImage(); [Message sent by forum member 'nathandennis' (nbd@...)] http://forums.java.net/jive/thread.jspa?messageID=367948 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: Scaling, Encoding, Loss of Qualityone thing,
param.setQuality(1.2F); quality can only be 0 -> 1.0 (0-100%) im not sure what effect that might have but might want to try it out. [Message sent by forum member 'qwertywin' (qwertywin@...)] http://forums.java.net/jive/thread.jspa?messageID=369945 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
| Free embeddable forum powered by Nabble | Forum Help |