Note that there are some explanatory texts on larger screens.

plurals
  1. POjpegs are corrupted when resampled with java imageIO
    primarykey
    data
    text
    <p>The JPEG Images that ImageIO generated view correctly on windows file explorer, as well as safari webbrowser, but in FireFox, the resampled images are clipped.</p> <p>How do I use ImageIO without corrupting the resamples?</p> <p>The code should resize image keeping aspect ratio, as well as do jpeg compression, the convert it to a byte [] array, which could be written to a socket.</p> <p>some of my code. in this snippet, I tried adding Jui library, but still the same issue.</p> <pre><code>public static BufferedImage imageistream; public void Resample(String child,double width,double height) throws Exception, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException, MissingParameterException, WrongParameterException { String imagePath = ""; if(this.is_mac_unix == true) { imagePath = this.path+"/"+child; } else { imagePath = this.path+"\\"+child; } PixelImage bmp = null; try { bmp = ToolkitLoader.loadViaToolkitOrCodecs(imagePath, true, null); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Resample resample = new Resample(); resample.setInputImage(bmp); double fixedRatio = width/height; if(((double)bmp.getWidth()/bmp.getHeight()) &gt;= fixedRatio) { resample.setSize((int)width,(int)(bmp.getHeight()/(bmp.getWidth()/width))); } else { resample.setSize((int)width,(int)(bmp.getWidth()/(bmp.getHeight()/height))); } resample.setFilter(Resample.FILTER_TYPE_LANCZOS3); resample.process(); PixelImage scaledImage = resample.getOutputImage(); Processor.imageistream = ImageCreator.convertToAwtBufferedImage(scaledImage); bmp = null; Runtime rt = Runtime.getRuntime(); rt.gc(); } ... ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ImageIO.write(Processor.imageistream, "jpg", baos); // ImageIO.write(Processor.imageistream, "png", baos); Works! } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } byte bytes[] = baos.toByteArray(); ByteArrayInputStream is = new ByteArrayInputStream(bytes); OutputStream os = (OutputStream)obj[1]; OutputStreamWriter writer = (OutputStreamWriter)obj[0]; byte[] buf= new byte[4096]; int c; try { while (true) { c= is.read(buf); if (c&lt;= 0) break; os.write(buf, 0, c); } writer.close(); os.close(); is.close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload