处理的是*.dwg吗?是的话用vb处理方便些.

解决方案 »

  1.   

    主要处理的是*.gif和*.jpg,也许还有*.bmp,好像格式倒是没有多大区别的,功能我可以去实现。
    问题是把上传图片的信息提取成二进制信息后,不知道怎么对二进制信息处理水印问题不过是一定要用JAVA的
      

  2.   

    package net.csdn.xdj.model.d050403;import java.io.*;
    import java.awt.*;
    import java.awt.image.*;
    import com.sun.image.codec.jpeg.*;
    /**
     * <p>加入水印信息</p>
     * <p>Title: community.csnd.net</p>
     * <p>Description: java问题解答</p>
     * <p>Copyright: Copyright (c) 2005</p>
     * <p>Company: 自由人</p>
     * @author 许德建(simonxuluo)
     * @version 1.0
     */
    public class Mark {
      public Mark() {
      }  public static ByteArrayOutputStream manipulateImage(String message,
          byte[] imageData) {
        ByteArrayOutputStream baos = null;
        Frame frame = null;
        Graphics graphics = null;
        try {
          frame = new Frame();
          frame.addNotify();
          MediaTracker mt = new MediaTracker(frame);
          Image image = Toolkit.getDefaultToolkit().createImage(imageData);
          mt.addImage(image, 0);
          mt.waitForAll();
          int w = image.getWidth(frame);
          int h = image.getHeight(frame);
          BufferedImage offscreen = new BufferedImage(w, h,
                                                      BufferedImage.TYPE_3BYTE_BGR);
          graphics = offscreen.getGraphics();
          graphics.drawImage(image, 0, 0, frame);
          graphics.setColor(Color.RED);
          graphics.setFont(new Font("宋体", Font.BOLD | Font.ITALIC, 20));
          graphics.drawString(message, 9, 29);
          graphics.setColor(Color.WHITE);
          graphics.drawString(message, 10, 30);
          baos = new ByteArrayOutputStream();
          JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.
              createJPEGEncoder(baos);
          encoder.encode(offscreen);
        }
        catch (InterruptedException e) {
          e.printStackTrace(System.out); //To change body of catch statement use File | Settings | File Templates.
        }
        catch (IOException e) {
          e.printStackTrace(System.out); //To change body of catch statement use File | Settings | File Templates.
        }
        finally {
          if (graphics != null) {
            graphics.dispose();
          }
          if (frame != null) {
            frame.removeNotify();
          }
        }
        return baos;
      }
    }
      

  3.   

    package net.csdn.xdj.servlet.d050403;import org.apache.struts.action.*;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.upload.FormFile;/**
     * <p>页面表单影射,Action FormBean</p>
     * <p>Title: community.csnd.net</p>
     * <p>Description: java问题解答</p>
     * <p>Copyright: Copyright (c) 2005</p>
     * <p>Company: 自由人</p>
     * @author 许德建(simonxuluo)
     * @version 1.0
     */
    public class UploadAFB
        extends ActionForm {
      private String theAction;
      private FormFile theFile;
      private String newFile;  public void setTheAction(String theAction) {
        this.theAction = theAction;
      }  public String getTheAction() {
        return this.theAction;
      }  public void setTheFile(FormFile theFile) {
        this.theFile = theFile;
      }  public void setNewFile(String newFile) {
        this.newFile = newFile;
      }  public FormFile getTheFile() {
        return this.theFile;
      }  public String getNewFile() {
        return newFile;
      }  public ActionErrors validate(ActionMapping mapping,
                                   HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (theAction != null) {
          if (theFile == null) {
            errors.add(errors.GLOBAL_ERROR, new ActionError("error", "没有指定上传文件"));
          }
          if (newFile == null & newFile.length() == 0) {
            errors.add(errors.GLOBAL_ERROR, new ActionError("error", "没有指定保存文件路径"));
          }
        }
        // verify
        return errors;
      }}
      

  4.   

    package net.csdn.xdj.servlet.d050403;import org.apache.struts.action.*;
    import javax.servlet.http.*;
    import org.apache.struts.upload.FormFile;
    import java.io.*;
    import net.csdn.xdj.model.d050403.Mark;/**
     * <p>上传处理,Action</p>
     * <p>Title: community.csnd.net</p>
     * <p>Description: java问题解答</p>
     * <p>Copyright: Copyright (c) 2005</p>
     * <p>Company: 自由人</p>
     * @author 许德建(simonxuluo)
     * @version 1.0
     */
    public class UploadImage
        extends Action {
      public ActionForward execute(ActionMapping mapping,
                                   ActionForm actionForm,
                                   HttpServletRequest request,
                                   HttpServletResponse response) {
        UploadAFB form = (UploadAFB) actionForm;
        String theAction = form.getTheAction();
        form.setTheAction("uploadImage");
        if (theAction == null) {
          theAction = "";
        }
        else if (theAction.equals("uploadImage")) {
          FormFile file = form.getTheFile();
          File newFile = new File(form.getNewFile());
          if (file == null || newFile == null) {
            return mapping.getInputForward();
          }
          try {
            ByteArrayOutputStream baos = Mark.manipulateImage("许德建",
                file.getFileData());
            FileOutputStream fos = new FileOutputStream(newFile);
            baos.writeTo(fos);
            fos.close();
            baos.close();
            request.setAttribute("message", "上传成功");
            return mapping.findForward("response");
          }
          catch (FileNotFoundException ex) {
            // error handle
          }
          catch (IOException ex) {
            // error handle
          }
        }
        return mapping.getInputForward();
      }
    }
      

  5.   

    simonxuluo(爱江山更爱美人)
    谢谢了
    这几天在忙着,今天才上来,等会去看再问一下
    graphics.drawString(message, 9, 29);
    我如何才能控制message字符串的宽度随着图片的大小而自动调整
    就是随着图片的width与height设置字体的大小,而不是定20
    graphics.setFont(new Font("宋体", Font.BOLD | Font.ITALIC, 20));发贴这么长时间也没有结,不好意思,下午我就结贴,