Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 1999-2101 Alibaba Group.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.simpleimage.util;
JAI图片处理辅助类

Author(s):
xianmao.hexm 2007-12-13 下午02:34:51
public class ImageDrawHelper {
    static {
        JAIRegisterHelper.register();
    }
    private static ImageLog log = ImageLog.getLog(ImageDrawHelper.class);
    public static void drawText(BufferedImage srcDrawTextParameter dp) {
        if (dp == null || dp.getTextInfo() == null || dp.getTextInfo().size() == 0) {
            return;
        }
        int width = src.getWidth();
        int height = src.getHeight();
        Graphics2D graphics = src.createGraphics();
        try {
            for (DrawTextItem item : dp.getTextInfo()) {
                if (item != null) {
                    item.drawText(graphicswidthheight);
                }
            }
        } finally {
            if (graphics != null) {
                graphics.dispose();
            }
            .debug("After drawText"src);
        }
    }
    public static BufferedImage drawWatermark(BufferedImage srcWatermarkParameter param) {
        if (param == null) {
            return src;
        }
        if (param.getX() > src.getWidth() || param.getY() > src.getHeight()) {
            throw new IllegalArgumentException("Watermark's coordinate(" + param.getX() + ", " + param.getY()
                                               + ") exceed " + "the dimension of background image(" + src.getWidth()
                                               + ", " + src.getHeight() + ")");
        }
        Graphics2D graphics = src.createGraphics();
        Composite oldComposite = graphics.getComposite();
        graphics.setComposite(AlphaComposite.getInstance(.param.getAlpha()));
        try {
            graphics.drawImage(param.getWatermark().getAsBufferedImage(), nullparam.getX(), param.getY());
        } finally {
            if (graphics != null) {
                graphics.setComposite(oldComposite);
                graphics.dispose();
            }
        }
        return src;
    }
New to GrepCode? Check out our FAQ X