Exemple #1
0
    def saveImageFile(self, fileName, width=None, height=None, rawData=None):
        if width == None:
            width = self.width
        if height == None:
            height = self.height
        if rawData == None:
            rawData = self.rawData

#		Rend an image
#		Create a buffered image in which to draw
#		bufferedImage =  BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
#		bufferedImage.setRGB(0, 0, width, height, rawData, 0, width);

        bufferedImage = BufferedImage(width, height,
                                      BufferedImage.TYPE_BYTE_INDEXED)
        #		bufferedImage =  BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
        bufferedImage.getRaster().setDataElements(0, 0, width, height, rawData)

        #		Create a graphics contents on the buffered image, draw something and then dispose it
        #		g2d = bufferedImage.createGraphics();
        #		g2d.setColor(Color.white);
        #		g2d.fillRect(0, 0, width, height);
        #		g2d.setColor(Color.black);
        #		g2d.fillOval(0, 0, width, height);
        #		g2d.dispose();

        #		Save as PNG
        file = File(fileName)
        ImageIO.write(bufferedImage, "png", file)
        return
Exemple #2
0
 def image(self):
     w = self.getWidth();
     h = self.getHeight();
     non_black_withe_image = BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB)
     self.paint(non_black_withe_image.getGraphics())
     raster=non_black_withe_image.getRaster()
     bi = BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY)
     write_raster = bi.getRaster()
     c = array.zeros('i', 4)
     on=wc = array.zeros('i', 1)
     off=array.zeros('i', 1)
     off[0]=1
     for x in range(w):
         for y in range(h):
             c = raster.getPixel(x,y,c)
             if sum(c)!=1020:
                 write_raster.setPixel(x,y, on)
             else:
                 write_raster.setPixel(x,y, off)
     return bi;
Exemple #3
0
 def image(self):
     w = self.getWidth()
     h = self.getHeight()
     non_black_withe_image = BufferedImage(w, h,
                                           BufferedImage.TYPE_INT_ARGB)
     self.paint(non_black_withe_image.getGraphics())
     raster = non_black_withe_image.getRaster()
     bi = BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY)
     write_raster = bi.getRaster()
     c = array.zeros('i', 4)
     on = wc = array.zeros('i', 1)
     off = array.zeros('i', 1)
     off[0] = 1
     for x in range(w):
         for y in range(h):
             c = raster.getPixel(x, y, c)
             if sum(c) != 1020:
                 write_raster.setPixel(x, y, on)
             else:
                 write_raster.setPixel(x, y, off)
     return bi
 def  main(self, args):
     width = 400;
     height = 400;
     im =  BufferedImage(width,height,BufferedImage.TYPE_BYTE_BINARY);
     raster = im.getRaster();
     for h in range(height):
         for w in range(width):
             if (h / 50 + w / 50) % 2 == 0:
                 raster.setSample(w,h,0,0);
             else:
                 raster.setSample(w,h,0,1);
     try:
         ImageIO.write(im,"PNG", File("checkboard.png"));
     except IOException:
         print "can not open the file"