本文整理汇总了Java中ij.io.FileSaver.saveAsJpeg方法的典型用法代码示例。如果您正苦于以下问题:Java FileSaver.saveAsJpeg方法的具体用法?Java FileSaver.saveAsJpeg怎么用?Java FileSaver.saveAsJpeg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.io.FileSaver
的用法示例。
在下文中一共展示了FileSaver.saveAsJpeg方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import ij.io.FileSaver; //导入方法依赖的package包/类
public static void convert(File in, File out, Integer size, String toFormat) throws Throwable {
ImagePlus img = IJ.openImage(in.getAbsolutePath());
try {
int w = img.getWidth();
int h = img.getHeight();
double ratio = ((double) w) / ((double) h);
ImageProcessor ip = img.getProcessor();
if (size != null && size > 0) {
if (w >= h) {
if (w > size) {
img.setProcessor(ip.resize(size, (int) (size / ratio), true));
}
} else {
if (h > size) {
img.setProcessor(ip.resize((int) (ratio * size), size, true));
}
}
}
FileSaver fs = new FileSaver(img);
if ("PNG".equalsIgnoreCase(toFormat)) {
fs.saveAsPng(out.getAbsolutePath());
} else if ("JPG".equalsIgnoreCase(toFormat) || "JPEG".equalsIgnoreCase(toFormat)) {
fs.saveAsJpeg(out.getAbsolutePath());
} else {
throw new Exception("Unsupported format: " + toFormat);
}
} finally {
img.close();
}
}
示例2: save
import ij.io.FileSaver; //导入方法依赖的package包/类
/** Save an image in the format specified by {@param fileType}, which can be any of:
* "tif", "tiff", "zip", "gif", "jpg", "jpeg", "bmp", "pgm", "png", "raw".
*
* When saving as TIFF, if the image has more than 2 dimensions, it will be saved
* as a stack.
* @throws ImgLibException */
public static<T extends RealType<T> & NativeType<T>> boolean save(final Img<T> image, String fileType, final String path) throws ImgLibException {
// TODO: use LOCI for this
final ImagePlus imp = wrap(image);
final FileSaver saver = new FileSaver(imp);
fileType = fileType.toLowerCase();
if (fileType.equals("tif") || fileType.equals("tiff")) {
if (image.numDimensions() > 2) {
return saver.saveAsTiffStack(path);
}
return saver.saveAsTiff(path);
} else if (fileType.equals("zip"))
return saver.saveAsZip(path);
else if (fileType.equals("gif"))
return saver.saveAsGif(path);
else if (fileType.equals("jpg") || fileType.equals("jpeg"))
return saver.saveAsJpeg(path);
else if (fileType.equals("bmp"))
return saver.saveAsBmp(path);
else if (fileType.equals("pgm"))
return saver.saveAsPgm(path);
else if (fileType.equals("png"))
return saver.saveAsPng(path);
else if (fileType.equals("raw"))
return saver.saveAsRaw(path);
else
throw new RuntimeException("Unknown fileformat: " + fileType);
}