MemoryImageSource ms=new MemoryImageSource(292,171,java.awt.image.ColorModel.getRGBdefault(),tempImage,0,1);应该是这个的问题

解决方案 »

  1.   

    jdk文档上有个例子是这样的:This class is an implementation of the ImageProducer interface which uses an array to produce pixel values for an Image. Here is an example which calculates a 100x100 image representing a fade from black to blue along the X axis and a fade from black to red along the Y axis:  
    int w = 100;
    int h = 100;
    int pix[] = new int[w * h];
    int index = 0;
    for (int y = 0; y < h; y++) {
        int red = (y * 255) / (h - 1);
        for (int x = 0; x < w; x++) {
    int blue = (x * 255) / (w - 1);
    pix[index++] = (255 << 24) | (red << 16) | blue;
        }
    }
    Image img = createImage(new MemoryImageSource(w, h, pix, 0, w));
      

  2.   

    不是这个的问题!我试过了!因为我是在consle程序里面把它专成image对象的所以我怀疑是toolkit的问题,因为我觉得如果在applet中的话,默认的就有createimage方法,但是在consle程序里面就没有这个createimage()方法,只能用toolkit。会不会是这个的问题!?
      

  3.   

    我试过你的代码了,用的就是你的代码和MemoryImageSource中的代码,没有问题呀。
      

  4.   

    to: yayv(yayv) 
    但是我从生成的image,专成文件的时候怎么回事一片漆黑呢!我在本地试的时候,因为没有把image打成int[],直接把image保存成文件就没有问题,但是一旦打成int[]在专成image就有问题了!声称的图片一片漆黑!