当前位置: 首页>>代码示例>>Python>>正文


Python image.BufferedImage类代码示例

本文整理汇总了Python中java.awt.image.BufferedImage的典型用法代码示例。如果您正苦于以下问题:Python BufferedImage类的具体用法?Python BufferedImage怎么用?Python BufferedImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BufferedImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getScreenPanel

def getScreenPanel():
    global mainScreen
    global scrPanel
    if not scrPanel:
        mainScreen = JButton()
        cursorImg = BufferedImage(16,16,BufferedImage.TYPE_INT_ARGB)
        blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, Point(0,0), "blank cursor")
        mainScreen.setCursor(blankCursor)
        mainScreen.setPreferredSize(
                Dimension(700, 700))
        image = BufferedImage(700, 700, BufferedImage.TYPE_INT_ARGB)
        g = image.createGraphics()
        g.setColor(Color.BLACK)
        g.fillRect(0, 0, 700, 700)
        g.setColor(Color.WHITE)
        g.setFont(Font("Serif", Font.BOLD, 20))
        g.drawString("Move your mouse here to controlfocused device.", 50, 30)
        mainScreenImg = image
        mainScreen.setIcon(swing.ImageIcon(image))

        mouseListener = ScrMouseListener()
        mainScreen.addMouseListener(mouseListener)
        mainScreen.addMouseMotionListener(mouseListener)
        mainScreen.addMouseWheelListener(mouseListener)

        mainScreen.setFocusable(True)
        keyListener = ScrKeyListener()
        mainScreen.addKeyListener(keyListener)


        scrPanel = JPanel()
        scrPanel.setLayout(BoxLayout(scrPanel, BoxLayout.Y_AXIS))
        scrPanel.add(mainScreen)
        scrPanel.setFocusable(True)
    return scrPanel
开发者ID:sjp38,项目名称:ash,代码行数:35,代码来源:ashdi.py

示例2: __init__

   def __init__(self, filename, width=None, height=None): 
      """Create an image from a file, or an empty (black) image with specified dimensions."""
      
      # Since Python does not allow constructors with different signatures,
      # the trick is to reuse the first argument as a filename or a width.
      # If it is a string, we assume they want is to open a file.
      # If it is an int, we assume they want us to create a blank image.
      
      if type(filename) == type(""):  # is it a string?
         self.filename = filename        # treat is a filename
         self.image = BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB)  # create a dummy image
         self.read(filename)             # and read external image into ti
                  
      elif type(filename) == type(1): # is it a int?
      
         # create blank image with specified dimensions
         self.filename = "Untitled"
         self.width = filename       # holds image width (shift arguments)
         self.height = width         # holds image height
         self.image = BufferedImage(self.width, self.height, BufferedImage.TYPE_INT_RGB)  # holds image buffer (pixels)
      else:
         raise  TypeError("Image(): first argument must a filename (string) or an blank image width (int).")
         
      # display image
      self.display = JFrame()      # create frame window to hold image
      icon = ImageIcon(self.image) # wrap image appropriately for displaying in a frame
      container = JLabel(icon)         
      self.display.setContentPane(container)  # and place it

      self.display.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
      self.display.setTitle(self.filename)
      self.display.setResizable(False)
      self.display.pack()
      self.display.setVisible(True)
开发者ID:HenryStevens,项目名称:jes,代码行数:34,代码来源:image.py

示例3: resize

 def resize(self, image, width, height):
     bi = BufferedImage(width, height, BufferedImage.TRANSLUCENT)
     g2d = bi.createGraphics()
     g2d.addRenderingHints(RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY))
     g2d.drawImage(image, 0, 0, width, height, None)
     g2d.dispose()
     return bi;
开发者ID:anhnt4288,项目名称:PT-Manager,代码行数:7,代码来源:PTManager.py

示例4: scale_to_fill

def scale_to_fill(buffered_image):
    raster = buffered_image.getData()
    width = raster.getWidth()
    height = raster.getHeight()
    #Get extreem values from the image
    max_x = 0
    min_x = width
    max_y = 0
    min_y = height
    for x in range(0, width):
        for y in range(0,height):
            color = pixel_has_color(x,y, raster)
            if(color):
                if x > max_x:
                    max_x = x
                if x < min_x:
                    min_x = x
                if y > max_y:
                    max_y = y
                if y < min_y:
                    min_y = y
    #Cut out the part of image containing colored pixels
    sub_image = buffered_image.getSubimage(min_x, min_y, max_x-min_x+1,max_y-min_y+1)
    #Scale the image
    resized_image = BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY)
    g = resized_image.createGraphics()
    g.drawImage(sub_image, 0, 0, width, height, None)
    g.dispose()
    return resized_image
开发者ID:Jonny-James,项目名称:HandReco,代码行数:29,代码来源:image_preprocessor.py

示例5: outputFiles

 def outputFiles(self, filename, attachLogo=False, logoText=None):
     rendered = self.getTarget().screenshot()
     if attachLogo:
         from java.awt.image import BufferedImage
         from com.raytheon.uf.common.localization import PathManagerFactory
         noaa = 'pyViz/logos/noaalogo2.png'
         nws = 'pyViz/logos/nwslogo.png'
         pathMgr = PathManagerFactory.getPathManager()
         noaa = pathMgr.getStaticFile(noaa)
         nws = pathMgr.getStaticFile(nws)
         noaaImage = ImageIO.read(noaa)
         nwsImage = ImageIO.read(nws)
         height = rendered.getHeight() + noaaImage.getHeight()
         finalBuf = BufferedImage(rendered.getWidth(), height, BufferedImage.TYPE_INT_ARGB)
         graphics = finalBuf.createGraphics()
         graphics.drawImage(rendered, 0, 0, None)
         graphics.drawImage(noaaImage, 0, rendered.getHeight(), None)
         graphics.fillRect(noaaImage.getWidth(), rendered.getHeight(), rendered.getWidth() - noaaImage.getWidth() - nwsImage.getWidth(), rendered.getHeight())
         if logoText is not None:
             from java.awt import Color
             from com.raytheon.uf.viz.core.font import FontAdapter
             graphics.setColor(Color.BLACK)
             graphics.setFont(FontAdapter.getAWTFont(self.getTarget().getDefaultFont()))
             fm = graphics.getFontMetrics()
             textBounds = fm.getStringBounds(logoText, graphics)
             graphics.drawString(logoText, int((rendered.getWidth() - textBounds.getWidth()) / 2), \
                                 int(rendered.getHeight() + (noaaImage.getHeight() / 2) + textBounds.getHeight() / 2))
         graphics.drawImage(nwsImage, finalBuf.getWidth() - nwsImage.getWidth(), rendered.getHeight(), None)
         finalBuf.flush()
         self.outputImage(finalBuf, filename)
     else:
         self.outputImage(rendered, filename)
开发者ID:KeithLatteri,项目名称:awips2,代码行数:32,代码来源:GFEPainter.py

示例6: get_font_metrics

def get_font_metrics(font_name, font_size):
    from java.awt.image import BufferedImage
    from java.awt import Font

    tmp_img = BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)
    g = tmp_img.createGraphics()
    return g.getFontMetrics((Font(font_name, Font.PLAIN, int(font_size))))
开发者ID:kiwiroy,项目名称:nodebox,代码行数:7,代码来源:pyvector.py

示例7: setValue

 def setValue(self, value):
     if value == "":
         img = BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)
         g = img.getGraphics()
         g.setColor(Color.RED)
         g.fillOval(2, 2, 10, 10)
         self.setIcon(ImageIcon(img))
     else:
         self.setIcon(value)
开发者ID:floscher,项目名称:qat_script,代码行数:9,代码来源:QatDialog.py

示例8: resizeImage

 def resizeImage(self, fullSizeImage):
     bufferedImage = BufferedImage(SwingingMonkeyCommander._preferredWidth, SwingingMonkeyCommander._preferredHeight, BufferedImage.TRANSLUCENT)
     graphics2d = bufferedImage.createGraphics()
     graphics2d.addRenderingHints(RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY))
     graphics2d.drawImage(fullSizeImage, 0, 0, SwingingMonkeyCommander._preferredWidth, SwingingMonkeyCommander._preferredHeight, None)
     graphics2d.dispose()
     SwingingMonkeyCommander._widthScale = float(fullSizeImage.getWidth()) / float(bufferedImage.getWidth())
     SwingingMonkeyCommander._heightScale = float(fullSizeImage.getHeight()) / float(bufferedImage.getHeight())
     return bufferedImage
开发者ID:fejd,项目名称:SwingingMonkeyCommander,代码行数:9,代码来源:SwingingMonkeyCommander.py

示例9: saveToPNG

def saveToPNG(p,filename):
    from java.awt.image import BufferedImage
    from javax.imageio import ImageIO
    from java.io import File
    bi = BufferedImage(p.size.width, p.size.height, BufferedImage.TYPE_INT_ARGB) 
    g = bi.createGraphics()
    p.invalidate()
    p.validate()
    p.paint(g)
    g.dispose();
    ImageIO.write(bi,"png", File(filename));
开发者ID:CalSimCalLite,项目名称:CalLiteGUI,代码行数:11,代码来源:calibration_compare_plots.py

示例10: getIcon

 def getIcon(self):
     """Set the layer icon.
     """
     if self.iconf is not None:
         return self.iconf
     else:
         img = BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)
         g = img.getGraphics()
         g.setColor(Color.RED)
         g.fillOval(2, 2, 10, 10)
         return ImageIcon(img)
开发者ID:alex85k,项目名称:qat_script,代码行数:11,代码来源:error_layer.py

示例11: find_shape_sizes

    def find_shape_sizes(self, shape):
        shapeSizeInDocument = shape.getShapeRenderer().getSizeInPoints()
        width = shapeSizeInDocument.x # The width of the shape.
        height = shapeSizeInDocument.y # The height of the shape.
        shapeRenderedSize = shape.getShapeRenderer().getSizeInPixels(1.0, 96.0)

        image = BufferedImage(shapeRenderedSize.width, shapeRenderedSize.height, BufferedImage.TYPE_INT_RGB)

        gr = image.getGraphics()

        # Render shape onto the graphics object using the RenderToScale or RenderToSize methods of ShapeRenderer class.

        gr.dispose()
开发者ID:Aspose,项目名称:Aspose.Words-for-Java,代码行数:13,代码来源:RenderShapes.py

示例12: save_as_png

def save_as_png(p,filename):
    """
    saves plot window (G2Dialog) created by newPlot(title) method as a png graphics file
    """
    from java.awt.image import BufferedImage
    from javax.imageio import ImageIO
    from java.io import File
    bi = BufferedImage(p.size.width, p.size.height, BufferedImage.TYPE_INT_ARGB) 
    g = bi.createGraphics()
    p.invalidate()
    p.validate()
    p.paint(g)
    g.dispose();
    ImageIO.write(bi,"png", File(filename));
开发者ID:CalSimCalLite,项目名称:CalLiteGUI,代码行数:14,代码来源:model_obs_compare.py

示例13: snapshot

def snapshot(frame, box):
    bi = BufferedImage(box.width, box.height, BufferedImage.TYPE_INT_RGB)
    g = bi.createGraphics()
    g.translate(-box.x, -box.y)
    # all black! # frame.paintAll(g)
    # only swing components! # frame.paint(g)
    # only swing components! # frame.update(g)
    # together, also only swing and with errors
    ##frame.update(g)
    ##frame.paint(g)
    # locks the entire graphics machinery # frame.printAll(g)
    # Finally, the right one:
    SwingUtilities.invokeAndWait(PrintAll(frame, g))
    return bi
开发者ID:Mverp,项目名称:fiji,代码行数:14,代码来源:Record_Window.py

示例14: render_shape_to_graphics

    def render_shape_to_graphics(self, shape):
        r = shape.getShapeRenderer()

        # Find the size that the shape will be rendered to at the specified scale and resolution.
        shapeSizeInPixels = r.getSizeInPixels(1.0, 96.0)

        # Rotating the shape may result in clipping as the image canvas is too small. Find the longest side
        # and make sure that the graphics canvas is large enough to compensate for this.
        maxSide = Math.max(shapeSizeInPixels.width, shapeSizeInPixels.height)

        image = BufferedImage(int(maxSide * 1.25), int(maxSide * 1.25), BufferedImage.TYPE_INT_ARGB)

        # Rendering to a graphics object means we can specify settings and transformations to be applied to
        # the shape that is rendered. In our case we will rotate the rendered shape.
        gr = image.getGraphics()

        # Clear the shape with the background color of the document.
        gr.setBackground(shape.getDocument().getPageColor())
        gr.clearRect(0, 0, image.getWidth(), image.getHeight())
        # Center the rotation using translation method below
        gr.translate(image.getWidth() / 8, image.getHeight() / 2)
        # Rotate the image by 45 degrees.
        gr.rotate(45 * Math.PI / 180)
        # Undo the translation.
        gr.translate(-image.getWidth() / 8, -image.getHeight() / 2)

        # Render the shape onto the graphics object.
        r.renderToSize(gr, 0, 0, shapeSizeInPixels.width, shapeSizeInPixels.height)

        ImageIO.write(image, "png", File(self.dataDir + "TestFile.RenderToGraphics.png"))

        gr.dispose()

        print "Shape rendered to Graphics successfully."
开发者ID:Aspose,项目名称:Aspose.Words-for-Java,代码行数:34,代码来源:RenderShapes.py

示例15: main

 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"
开发者ID:Yinhai,项目名称:HandReco,代码行数:15,代码来源:CreateBWImageNoJAI.py


注:本文中的java.awt.image.BufferedImage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。