缩放图像（按比例缩放）<br>
缩放后默认为jpeg格式，此方法并不关闭流

@param srcImg 源图像来源流
@param destFile 缩放后的图像写出到的流
@param scale 缩放比例。比例大于1时为放大，小于1大于0为缩小
@throws IORuntimeException IO异常
@since 3.2.2
499803
public static void scale(Image srcImg, File destFile, float scale) throws IORuntimeException {
		write(scale(srcImg, scale), destFile);
	}
818945
private static long getScaledValue(FileBuffer buffer, int scale,
                                       long position)
        throws IOException
    {
        return getScaledValue(new byte[8], buffer, scale, position);
    }
55800
public static void writeJpg(Image image, ImageOutputStream destImageStream) throws IORuntimeException {
		write(image, IMAGE_TYPE_JPG, destImageStream);
	}
375858
public final void setSourceFile(final String srcFile) {
        if (SwingUtilities.isEventDispatchThread()) {
            setSourceFileIntern(srcFile);
        } else {
            try {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        setSourceFileIntern(srcFile);
                    }
                });
            } catch (final Exception ex) {
                ignore();
            }
        }
    }
43507
private void processStream(CameraPinholeBrown intrinsic , SimpleImageSequence<GrayU8> sequence , ImagePanel gui , long pauseMilli) {

		Font font = new Font("Serif", Font.BOLD, 24);

		Se3_F64 fiducialToCamera = new Se3_F64();
		int frameNumber = 0;
		while( sequence.hasNext() ) {
			long before = System.currentTimeMillis();
			GrayU8 input = sequence.next();
			BufferedImage buffered = sequence.getGuiImage();
			try {
				detector.detect(input);
			} catch( RuntimeException e ) {
				System.err.println("BUG!!! saving image to crash_image.png");
				UtilImageIO.saveImage(buffered,"crash_image.png");
				throw e;
			}

			Graphics2D g2 = buffered.createGraphics();

			for (int i = 0; i < detector.totalFound(); i++) {
				detector.getFiducialToCamera(i,fiducialToCamera);
				long id = detector.getId(i);
				double width = detector.getWidth(i);

				VisualizeFiducial.drawCube(fiducialToCamera,intrinsic,width,3,g2);
				VisualizeFiducial.drawLabelCenter(fiducialToCamera,intrinsic,""+id,g2);
			}
			saveResults(frameNumber++);

			if( intrinsicPath == null ) {
				g2.setColor(Color.RED);
				g2.setFont(font);
				g2.drawString("Uncalibrated",10,20);
			}

			gui.setImage(buffered);

			long after = System.currentTimeMillis();
			long time = Math.max(0,pauseMilli-(after-before));
			if( time > 0 ) {
				try { Thread.sleep(time); } catch (InterruptedException ignore) {}
			}
		}
	}
163911
public boolean write(File targetFile) throws IORuntimeException {
		final String formatName = FileUtil.extName(targetFile);
		if (StrUtil.isNotBlank(formatName)) {
			this.targetImageType = formatName;
		}
		
		if(targetFile.exists()) {
			targetFile.delete();
		}
		
		ImageOutputStream out = null;
		try {
			out = ImgUtil.getImageOutputStream(targetFile);
			return write(out);
		} finally {
			IoUtil.close(out);
		}
	}
598789
public void copyFile(final RelativeResource src, final RelativeResource dest)
		throws IOException {
		if (src.equals(dest)) {
			return;
		}
		LOG.debug("复制文件从 {} 到 {}", src, dest);
		File srcFile = getResource(src).getFile();
		if (!srcFile.exists()) {
			throw new FileNotFoundException(srcFile.getAbsolutePath());
		}
		File destFile = getResource(dest).getFile();
		deleteOldFile(destFile);
		FileUtils.copyFile(srcFile, destFile);
	}
381837
protected function _scaler($inputFile, $outputFile, $scaleType, $scale)
    {
        switch ($scaleType) {
            //skalowanie domyślne
            case 'default':
                $imgRes = \Mmi\Image\Image::inputToResource($inputFile);
                break;
            //skalowanie proporcjonalne do maksymalnego rozmiaru
            case 'scale':
                $v = explode('x', $scale);
                if (count($v) == 1 && is_numeric($v[0]) && intval($v[0]) > 0) {
                    $imgRes = \Mmi\Image\Image::scale($inputFile, $v[0]);
                } elseif (count($v) == 2 && is_numeric($v[0]) && intval($v[0]) > 0 && is_numeric($v[1]) && intval($v[1]) > 0) {
                    $imgRes = \Mmi\Image\Image::scale($inputFile, $v[0], $v[1]);
                }
                break;
            //skalowanie do maksymalnego X
            case 'scalex':
                $imgRes = \Mmi\Image\Image::scalex($inputFile, intval($scale));
                break;
            //skalowanie do maksymalnego Y
            case 'scaley':
                $imgRes = \Mmi\Image\Image::scaley($inputFile, intval($scale));
                break;
            //skalowanie z obcięciem
            case 'scalecrop':
                $v = explode('x', $scale);
                if (is_numeric($v[0]) && intval($v[0]) > 0 && is_numeric($v[1]) && intval($v[1]) > 0) {
                    $imgRes = \Mmi\Image\Image::scaleCrop($inputFile, $v[0], $v[1]);
                }
                break;
        }
        //brak obrazu
        if (!isset($imgRes)) {
            FrontController::getInstance()->getLogger()->warning('Unable to resize CMS file: ' . $outputFile);
            return;
        }
        //plik istnieje
        if (!file_exists(dirname($outputFile))) {
            try {
                mkdir(dirname($outputFile), 0777, true);
            } catch (\Mmi\App\KernelException $e) {
                FrontController::getInstance()->getLogger()->warning('Unable to create directories: ' . $e->getMessage());
                return;
            }
        }
        //określanie typu wyjścia
        $mimeType = \Mmi\FileSystem::mimeType($inputFile);
        //GIF
        if ($mimeType == 'image/gif') {
            imagealphablending($imgRes, false);
            imagesavealpha($imgRes, true);
            imagegif($imgRes, $outputFile);
            return;
        }
        //PNG (nieprzeźroczysty)
        if ($mimeType == 'image/png') {
            imagealphablending($imgRes, false);
            imagesavealpha($imgRes, true);
            imagepng($imgRes, $outputFile, 9);
            return;
        }
        //domyślnie JPEG
        imagejpeg($imgRes, $outputFile, intval(\App\Registry::$config->thumbQuality));
    }
533298
private static void putScaledValue(FileBuffer buffer, int scale,
                                       long position, long value)
        throws IOException
    {
        putScaledValue(new byte[8], buffer, scale, position, value);
    }
551468
public static void scale(Image srcImage, ImageOutputStream destImageStream, int width, int height, Color fixedColor) throws IORuntimeException {
		writeJpg(scale(srcImage, width, height, fixedColor), destImageStream);
	}
856357
public static void pressImage(InputStream srcStream, OutputStream destStream, Image pressImg, int x, int y, float alpha) {
		pressImage(read(srcStream), getImageOutputStream(destStream), pressImg, x, y, alpha);
	}
1243389
public void setRetryImage(int resourceId, ScalingUtils.ScaleType scaleType) {
    setRetryImage(mResources.getDrawable(resourceId), scaleType);
  }
1205593
private static void setDPI(IIOMetadata metadata, int dpi, String formatName)
            throws IIOInvalidTreeException
    {
        IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(MetaUtil.STANDARD_METADATA_FORMAT);

        IIOMetadataNode dimension = getOrCreateChildNode(root, "Dimension");

        // PNG writer doesn't conform to the spec which is
        // "The width of a pixel, in millimeters"
        // but instead counts the pixels per millimeter
        float res = "PNG".equals(formatName.toUpperCase())
                    ? dpi / 25.4f
                    : 25.4f / dpi;

        IIOMetadataNode child;

        child = getOrCreateChildNode(dimension, "HorizontalPixelSize");
        child.setAttribute("value", Double.toString(res));

        child = getOrCreateChildNode(dimension, "VerticalPixelSize");
        child.setAttribute("value", Double.toString(res));

        metadata.mergeTree(MetaUtil.STANDARD_METADATA_FORMAT, root);
    }
265258
public static void compress(File imageFile, File outFile, float quality) throws IORuntimeException {
		Img.from(imageFile).setQuality(quality).write(outFile);
	}
1156901
public final void mOCTAL_ESC() throws RecognitionException {
        try {
            // MessageFilter.g:232:5: ( '\\\\' ( '0' .. '3' ) ( '0' .. '7' ) ( '0' .. '7' ) | '\\\\' ( '0' .. '7' ) ( '0' .. '7' ) | '\\\\' ( '0' .. '7' ) )
            int alt18=3;
            int LA18_0 = input.LA(1);

            if ( (LA18_0=='\\') ) {
                int LA18_1 = input.LA(2);

                if ( ((LA18_1 >= '0' && LA18_1 <= '3')) ) {
                    int LA18_2 = input.LA(3);

                    if ( ((LA18_2 >= '0' && LA18_2 <= '7')) ) {
                        int LA18_4 = input.LA(4);

                        if ( ((LA18_4 >= '0' && LA18_4 <= '7')) ) {
                            alt18=1;
                        }
                        else {
                            alt18=2;
                        }
                    }
                    else {
                        alt18=3;
                    }
                }
                else if ( ((LA18_1 >= '4' && LA18_1 <= '7')) ) {
                    int LA18_3 = input.LA(3);

                    if ( ((LA18_3 >= '0' && LA18_3 <= '7')) ) {
                        alt18=2;
                    }
                    else {
                        alt18=3;
                    }
                }
                else {
                    NoViableAltException nvae =
                        new NoViableAltException("", 18, 1, input);

                    throw nvae;

                }
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 18, 0, input);

                throw nvae;

            }
            switch (alt18) {
                case 1 :
                    // MessageFilter.g:232:9: '\\\\' ( '0' .. '3' ) ( '0' .. '7' ) ( '0' .. '7' )
                    {
                    match('\\'); 

                    if ( (input.LA(1) >= '0' && input.LA(1) <= '3') ) {
                        input.consume();
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        recover(mse);
                        throw mse;
                    }


                    if ( (input.LA(1) >= '0' && input.LA(1) <= '7') ) {
                        input.consume();
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        recover(mse);
                        throw mse;
                    }


                    if ( (input.LA(1) >= '0' && input.LA(1) <= '7') ) {
                        input.consume();
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        recover(mse);
                        throw mse;
                    }


                    }
                    break;
                case 2 :
                    // MessageFilter.g:233:9: '\\\\' ( '0' .. '7' ) ( '0' .. '7' )
                    {
                    match('\\'); 

                    if ( (input.LA(1) >= '0' && input.LA(1) <= '7') ) {
                        input.consume();
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        recover(mse);
                        throw mse;
                    }


                    if ( (input.LA(1) >= '0' && input.LA(1) <= '7') ) {
                        input.consume();
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        recover(mse);
                        throw mse;
                    }


                    }
                    break;
                case 3 :
                    // MessageFilter.g:234:9: '\\\\' ( '0' .. '7' )
                    {
                    match('\\'); 

                    if ( (input.LA(1) >= '0' && input.LA(1) <= '7') ) {
                        input.consume();
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        recover(mse);
                        throw mse;
                    }


                    }
                    break;

            }

        }
        finally {
        	// do for sure before leaving
        }
    }
624615
public static void cut(Image srcImage, ImageOutputStream destImageStream, Rectangle rectangle) throws IORuntimeException {
		writeJpg(cut(srcImage, rectangle), destImageStream);
	}
10675
public static boolean write(Image image, String imageType, ImageOutputStream destImageStream, float quality) throws IORuntimeException {
		if (StrUtil.isBlank(imageType)) {
			imageType = IMAGE_TYPE_JPG;
		}

		final ImageWriter writer = getWriter(image, imageType);
		return write(toBufferedImage(image, imageType), writer, destImageStream, quality);
	}