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


Python BufferedImage.getWidth方法代码示例

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


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

示例1: render_shape_to_graphics

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getWidth [as 别名]
    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,代码行数:36,代码来源:RenderShapes.py

示例2: outputFiles

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getWidth [as 别名]
 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,代码行数:34,代码来源:GFEPainter.py

示例3: get_image

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getWidth [as 别名]
    def get_image(self):
        """Generate a BufferedImage representing the current environment, for use in
        interactivemode display."""

        # copy map
        bitmap = BufferedImage(self.map.getColorModel(), self.map.copyData(None), False, None);

        # draw agent
        graphics = bitmap.createGraphics()
        graphics.setColor(Color.orange)
        agentsize = 0.2
        x, y = self.pt_to_pixel((self.state[0] - agentsize / 2, self.state[1] + agentsize / 2))

        graphics.fillRect(x, y, int(agentsize * bitmap.getWidth() / self.imgsize[0]), int(agentsize * bitmap.getHeight() / self.imgsize[1]))

        return bitmap
开发者ID:Seanny123,项目名称:HRL_1.0,代码行数:18,代码来源:placecell_bmp.py

示例4: addSS

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getWidth [as 别名]
 def addSS(self,event):
     clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
     try:
         image = clipboard.getData(DataFlavor.imageFlavor)
     except:
         self.popup("Clipboard not contains image")
         return
     vulnPath = self.projPath.getText() + "/" + self.clearStr(self.vulnName.getText())
     if not os.path.exists(vulnPath):
         os.makedirs(vulnPath)
     name = self.clearStr(self.vulnName.getText()) + str(random.randint(1, 99999))+".jpg"
     fileName = self.projPath.getText()+"/"+ self.clearStr(self.vulnName.getText()) + "/" + name
     file = File(fileName)
     bufferedImage = BufferedImage(image.getWidth(None), image.getHeight(None), BufferedImage.TYPE_INT_RGB);
     g = bufferedImage.createGraphics();
     g.drawImage(image, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), Color.WHITE, None);
     ImageIO.write(bufferedImage, "jpg", file)
     self.addVuln(self)
     self.ssList.setSelectedValue(name,True)
开发者ID:anhnt4288,项目名称:PT-Manager,代码行数:21,代码来源:PTManager.py

示例5: indices

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getWidth [as 别名]
class Image:
   """Holds an image of RGB pixels accessed by column and row indices (col, row).  
      Origin (0, 0) is at upper left."""
      
# QUESTION:  For efficiency, should we also extract and save self.pixels (at image reading time)?
# Also make setPixel(), getPixel(), setPixels() and getPixels() work on/with self.pixels.  
# And when writing, use code in current setPixels() to update image buffer, before writing it out?
# This is something to try.
   
   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)

 
   def getWidth(self):
      """Returns the width of the image.""" 
      
      return self.width
      
   def getHeight(self):
      """Returns the height of the image.""" 
      
      return self.height
      
   def getPixel(self, col, row):
      """Returns a list of the RGB values for this pixel, e.g., [255, 0, 0].""" 
      
      # Obsolete - convert the row so that row zero refers to the bottom row of pixels.
      #row = self.height - row - 1

      color = Color(self.image.getRGB(col, row))  # get pixel's color
      return [color.getRed(), color.getGreen(), color.getBlue()]  # create list of RGB values (0-255)

   def setPixel(self, col, row, RGBlist):
      """Sets this pixel's RGB values, e.g., [255, 0, 0].""" 
      
      # Obsolete - convert the row so that row zero refers to the bottom row of pixels.
      #row = self.height - row - 1

      color = Color(RGBlist[0], RGBlist[1], RGBlist[2])  # create color from RGB values
      self.image.setRGB(col, row, color.getRGB())


   def getPixels(self):
      """Returns a 2D list of pixels (col, row) - each pixel is a list of RGB values, e.g., [255, 0, 0].""" 
      
      pixels = []                      # initialize list of pixels
      #for row in range(self.height-1, 0, -1):   # load pixels from image      
      for row in range(0, self.height):   # load pixels from image      
         pixels.append( [] )              # add another empty row
         for col in range(self.width):    # populate row with pixels    
            # RGBlist = self.getPixel(col, row)   # this works also (but slower)    
            color = Color(self.image.getRGB(col, row))  # get pixel's color
            RGBlist = [color.getRed(), color.getGreen(), color.getBlue()]  # create list of RGB values (0-255)
            pixels[-1].append( RGBlist )   # add a pixel as (R, G, B) values (0-255, each)

      # now, 2D list of pixels has been created, so return it
      return pixels

   def setPixels(self, pixels):
      """Sets image to the provided 2D list of pixels (col, row) - each pixel is a list of RGB values, e.g., [255, 0, 0].""" 
      
      self.height = len(pixels)        # get number of rows
      self.width  = len(pixels[0])     # get number of columns (assume all columns have same length
      
      #for row in range(self.height-1, 0, -1):   # iterate through all rows      
      for row in range(0, self.height):   # iterate through all rows     
         for col in range(self.width):    # iterate through every column on this row
         
#.........这里部分代码省略.........
开发者ID:HenryStevens,项目名称:jes,代码行数:103,代码来源:image.py

示例6: resizeImage

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getWidth [as 别名]
 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,代码行数:11,代码来源:SwingingMonkeyCommander.py


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