[email protected]你用web service,把图形数据(byte[]数组)用base64编码再用http传,较妥

解决方案 »

  1.   

    zzhangwa(化石和石头) 你的邮件地址是不是错误了?!
      

  2.   

    没看全,感觉代码挺乱。
    但是问题找出来了,你的sendGraph()方法的本来目的是用来远程传送图像是不是?但是你传送的Graphics对象,这么做是不可以的,原因一,这个对象能串行化吗?(不能)原因二,其实无论什么情况下你都无法传送Graphics对象,因为它是一个绘图句柄,相当于Windows中的DC。
    解决办法:总之你得把这个思路推翻,你试试串行化一个Image然后用于传送(我没试过,有其他朋友知道这个方法行不通或者有更好的方法请指出)。希望你尽快把问题解决!
      

  3.   

    i am interested in it, please send me one copy to [email protected]
      

  4.   

    路过在顶一下
    我关键是怎么可以把画图板的图像信息保存为可以传送的Image之类的对象呢?!
      

  5.   

    路过在顶一下
    我关键是怎么可以把画图板的图像信息保存为可以传送的Image之类的对象呢?!
      

  6.   

    要达到你的目的不是一定要传送Image对象的,可以传送Image的URL,由接收端解释为Image对象!
      

  7.   

    那我也要先把它保存为image呀,请问有什么方法可以做出这样的转换呢?!
      

  8.   

    哦是的,这个我牵考虑了,要保存Image同样需要可串行化。
    给你两个回答仅供参考:
    (1)仔细查一下Java API看一下是否有其他类可以实现,(主要是BufferedImage及其子类,以及java.awt.image包中的内容,可能真正实现起来比较复杂)
    (2)就你的要求的话,你传送的无非是些规则的图形,不妨保存Image的关键信息,比如位置、大小、颜色等等,再由接收端根据这些信息解释为正确的图形!可以考虑一下,这样的话就比较容易了,你说呢?
      

  9.   

    喔是呀。可以试试喔。。是否可以考虑每次鼠标拖动都产生事件,检查当前figure类型,然后把位置和figure类型传过去,然后在学生端绘制。另外,老师端按clear按钮,学生端也应该清空画板,那该怎么实现呢!?
    我的老师提供的接口是用象素数组传的我自己看书,象素数组那节没有看明白^_^b
    那又是怎样的方法呢?!
      

  10.   

    import java.awt.*;
    import java.awt.image.*;public class MyApplet extends Applet
    {
    ....
    ....  whatever ....
    ....Image greyscaleImage = null;public int[] convertToGreyscale(Image image, int width, int height)
    {
     int pixels[] = new int[width*height];
     try
        {
        // *********************************************
        // ***************** I CHANGE THIS *************
        // *********************************************
        PixelGrabber pG = new PixelGrabber(image,
                          0,0,width,height,pixels,0,width);
        if (pG.grabPixels())
           {
           for (int cnt = 0; cnt < pixels.length; cnt++) 
               {
               int alpha = (pixels[cnt] >> 24) & 0xff;
               int red   = (pixels[cnt] >> 16) & 0xff;
               int green = (pixels[cnt] >>  8) & 0xff;
               int blue  = (pixels[cnt]      ) & 0xff;
               int all = (int) ((red+green+blue)/3);           pixels[cnt]=(alpha << 24) + (all << 16) + 
                           (all << 8) + all;
               }
            }
            { System.out.println("Cannot grab pixel"); }    
        }
     catch(Exception e) { System.out.println("PixelGrabber is interrupted");}    
     return pixels;
    }public void init()
    {
      Image img =  ... get the image from anywhere ...;  // get size of the original image
      int width=img.getWidth(this);
      int height=img.getHeight(this);  // pixels is array of int[], the greyscale colors
      int pixels[] = convertToGreyscale(img, width, height);  // now, creating greyscaleImage
      greyscaleImage = this.createImage(new MemoryImageSource(width, height, pixels, 0,width));  repaint();
    }public void paint(Graphics gr)
    {
     // put the greyscale image to screen when ready
     if (greyscaleImage!=null)
        gr.drawImage(greyscaleImage, 0 , 0, this);
    }
    ......
    ...... bla bla bla whatever
    ......
    }
      

  11.   

    convert to the image or graphics to byte array.
      

  12.   

    (2003-05-14 18:37:32)   肥嘟嘟同学
    怎么能取到画板信息存为image对象呢!?
    (通过服务器中转) 
    (2003-05-14 18:51:59)   肥嘟嘟同学
    对象素数组工作原理还不是太明白请指点 
    (通过服务器中转)
      

  13.   

    http://asia.cnet.com/builder/program/java/0,39009364,39099280,00.htm
      

  14.   

    to takecare(大厅):
    我把DrawFigurePanel方法改成下面那样,发现bufferedImage截的是屏幕信息,我切换窗口,bufferedImage的内容就改变了,而且点击菜单,菜单的内容也显示在里头。我怎么才可以使bufferedImage只对画板对象截图呢?!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.image.*;public class DrawFigurePanel extends JPanel {
      public Vector figures = new Vector(10,10);
      public Figure figure = null;
      BufferedImage bi = new BufferedImage(800,600,BufferedImage.TYPE_INT_RGB);
      Graphics g = bi.createGraphics( );
      public DrawFigurePanel() {
        try {
          jbInit();
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
      }
      void jbInit() throws Exception {
        this.setBackground(UIManager.getColor("window"));
        this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            this_mouseDragged(e);
          }
        });
        this.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            this_mouseClicked(e);
          }
          public void mousePressed(MouseEvent e) {
            this_mousePressed(e);
          }
          public void mouseReleased(MouseEvent e) {
            this_mouseReleased(e);
          }
        });
      }
      Image greyscaleImage = null;  public int[] convertToGreyscale(Image image, int width, int height)
      {
       int pixels[] = new int[width*height];
       try
          {      PixelGrabber pG = new PixelGrabber(image,
                            0,0,width,height,pixels,0,width);
          if (pG.grabPixels())
             {
             for (int cnt = 0; cnt < pixels.length; cnt++)
                 {
                 int alpha = (pixels[cnt] >> 24) & 0xff;
                 int red   = (pixels[cnt] >> 16) & 0xff;
                 int green = (pixels[cnt] >>  8) & 0xff;
                 int blue  = (pixels[cnt]      ) & 0xff;
                 int all = (int) ((red+green+blue)/3);             pixels[cnt]=(alpha << 24) + (all << 16) +
                             (all << 8) + all;
                 }
              }
              { System.out.println("Cannot grab pixel"); }
          }
       catch(Exception e) { System.out.println("PixelGrabber is interrupted");}
       return pixels;
      }  public void init()
      {
        Image img =  bi;    // get size of the original image
        int width=img.getWidth(this);
        int height=img.getHeight(this);    // pixels is array of int[], the greyscale colors
        int pixels[] = convertToGreyscale(img, width, height);    // now, creating greyscaleImage
        greyscaleImage = this.createImage(new MemoryImageSource(width, height, pixels, 0,width));    repaint();
      }  public void paint(Graphics gr)
      {
       // put the greyscale image to screen when ready
       if (greyscaleImage!=null)
          gr.drawImage(greyscaleImage, 0 , 0, 800,600,this);}
      void this_mouseClicked(MouseEvent e) {
        if(figure == null)
          return;
        //Graphics g = this.getGraphics() ;
        g.setXORMode(Color.green);
        if(figure instanceof LineFigure){
          LineFigure lineFigure = (LineFigure)figure;
          lineFigure.draw(g);
          figures.add(lineFigure.clone());
        }
        if(figure instanceof RectangleFigure){
          RectangleFigure rectangleFigure = (RectangleFigure)figure;
          rectangleFigure.draw(g);
          figures.add(rectangleFigure.clone());
        }
        if(figure instanceof OvalFigure){
          OvalFigure ovalFigure = (OvalFigure)figure;
          ovalFigure.draw(g);
          figures.add(ovalFigure.clone());
        }
      }  void this_mouseDragged(MouseEvent e) {
        if(figure == null)
          return;
        Graphics g = this.getGraphics();
        g.setXORMode(Color.green);
        if(figure instanceof LineFigure){
          LineFigure lineFigure = (LineFigure)figure;
          if(lineFigure.firstDraw){
            lineFigure.draw(g);
            lineFigure.firstDraw = false;
          }else{
            lineFigure.draw(g);
            lineFigure.endPoint = e.getPoint();
            lineFigure.draw(g);
          }
        }
        if(figure instanceof RectangleFigure){
          RectangleFigure rectangleFigure = (RectangleFigure)figure;
          if(rectangleFigure.firstDraw){
            rectangleFigure.draw(g);
            rectangleFigure.firstDraw = false;
          }else{
            rectangleFigure.draw(g);
            rectangleFigure.endPoint = e.getPoint();
            rectangleFigure.draw(g);
          }
        }
        if(figure instanceof OvalFigure){
          OvalFigure ovalFigure = (OvalFigure)figure;
          if(ovalFigure.firstDraw){
            ovalFigure.draw(g);
            ovalFigure.firstDraw = false;
          }else{
            ovalFigure.draw(g);
            ovalFigure.endPoint = e.getPoint();
            ovalFigure.draw(g);
          }
        }  }  void this_mousePressed(MouseEvent e) {
        if(figure != null){
          figure.startPoint = e.getPoint();
          figure.endPoint = e.getPoint();
          figure.firstDraw = true;
        }
      }  void this_mouseReleased(MouseEvent e) {
        if(figure instanceof LineFigure){
          LineFigure lineFigure = (LineFigure)figure;
          figures.add(lineFigure.clone());
        }
        if(figure instanceof RectangleFigure){
          RectangleFigure rectangleFigure = (RectangleFigure)figure;
          figures.add(rectangleFigure.clone());
        }
        if(figure instanceof OvalFigure){
          OvalFigure ovalFigure = (OvalFigure)figure;
          figures.add(ovalFigure.clone());
        }
      }  protected void paintComponent(Graphics parm1) {
        /**@todo: Override this javax.swing.JComponent method*/
        super.paintComponent( parm1);
        parm1.setXORMode(Color.green);
        int i;
        for(i=0;i<figures.size();i++){
          Object x = figures.get(i);
          if(x instanceof LineFigure){
            LineFigure lineFigure = (LineFigure)x;
            lineFigure.draw(parm1);
          }
          if(x instanceof RectangleFigure){
            RectangleFigure rectFigure = (RectangleFigure)x;
            rectFigure.draw(parm1);
          }
          if(x instanceof OvalFigure){
            OvalFigure ovalFigure = (OvalFigure)x;
            ovalFigure.draw(parm1);
          }
        }
      }
    }
      

  15.   

    You know I am not good at GUI. sigh!
    But this is a chance for me to learn AWT. xixi.
    If I am available, I will study your code. 
    Good luck!
      

  16.   

    http://cn.sun.com/developers/technicalArticles/rmi-corba/
    这是一个rmi文件下载的例子
    不知对你有没有帮助,我没太仔细看你的要求,不过可以先把图像文件载到本地
      

  17.   

    谢谢 takecare(大厅)和 Veeve() 的意见和帮忙^_^
    我的问题已经解决了,我最后采用了传向量的方法把图形一次传过去了^_^
    现在我结贴了