6 import com.sun.image.codec.jpeg.*;
7 import java.awt.image.*;
16 public static final int DEFAULT_QUALITY = 75;
17 private static int quality;
19 static {
setQuality(ij.Prefs.getInt(ij.Prefs.JPEG, DEFAULT_QUALITY));}
21 public void run(String arg) {
30 void saveAsJpeg(
ImagePlus imp, OutputStream f) {
32 int width = imp.getWidth();
33 int height = imp.getHeight();
34 BufferedImage bi =
new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
36 Graphics g = bi.createGraphics();
37 g.drawImage(imp.
getImage(), 0, 0, null);
39 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(f);
40 JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
41 param.setQuality((
float)(quality/100.0),
true);
42 encoder.encode(bi, param);
50 void saveAsJpeg(ImagePlus imp, String path) {
52 FileOutputStream f =
new FileOutputStream(path);
54 }
catch (Exception e) {
55 IJ.showMessage(
"Jpeg Writer",
""+e);
59 public byte[] getJpegContents(ImagePlus imp) {
60 ByteArrayOutputStream f =
new ByteArrayOutputStream();
62 return f.toByteArray();
69 quality = jpegQuality;
70 if (quality<0) quality = 0;
71 if (quality>100) quality = 100;
74 public static int getQuality() {