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


Python BufferedImage.getGraphics方法代码示例

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


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

示例1: render_shape_to_graphics

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [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: setValue

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

示例3: getIcon

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

示例4: find_shape_sizes

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

示例5: PanTool

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
class PanTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		self.start_point = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.drawLine(16,0,16,32)
		g.drawLine(0,16,32,16)
		g.drawLine(16,0,10,6)
		g.drawLine(16,0,22,6)
		g.drawLine(0,16,6,10)
		g.drawLine(0,16,6,22)
		g.drawLine(16,32,10,26)
		g.drawLine(16,32,22,26)
		g.drawLine(32,16,26,10)
		g.drawLine(32,16,26,22)
	def mousePressed(self, locationOnScreen, g) :
		self.last_point = locationOnScreen
		return ""
	def mouseHovered(self, locationOnScreen, g) :
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		dx = -(locationOnScreen.x - self.last_point.x)
		dy = -(locationOnScreen.y - self.last_point.y)
		self.last_point = locationOnScreen
		return "%d,%d" % (dx, dy)
	def mouseReleased(self, locationOnScreen, g) :
		dx = -(locationOnScreen.x - self.last_point.x)
		dy = -(locationOnScreen.y - self.last_point.y)
		self.last_point = None
		return "%d,%d" % (dx, dy)
	def draw(self, s, g) :
		return None
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "Pan"
	def getTooltip(self) :
		return "move to a new section of the canvas defined by the starting point and the point at which the mouse was released"
	def getToolID(self) :
		return 'pan'
开发者ID:bkap,项目名称:MICT,代码行数:46,代码来源:pantool.py

示例6: image

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
 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;
开发者ID:Jonny-James,项目名称:HandReco,代码行数:22,代码来源:paint_area.py

示例7: getListCellRendererComponent

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
 def getListCellRendererComponent(self, list_, value, index, isSelected, cellHasFocus):
     """ generated source for method getListCellRendererComponent """
     setHorizontalAlignment(JLabel.LEFT)
     if isSelected:
         setBackground(list_.getSelectionBackground())
         setForeground(list_.getSelectionForeground())
     else:
         setBackground(list_.getBackground())
         setForeground(list_.getForeground())
     if value == None:
         return self
     presence = self.thePresenceManager.getPresence(value.__str__())
     status = presence.getStatus()
     if status != None:
         status = status.lower()
     iconSize = 20
     img = BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB)
     g = img.getGraphics()
     g.setColor(getBackground())
     g.fillRect(0, 0, iconSize, iconSize)
     if status == None:
         g.setColor(Color.GRAY)
     elif status == "available":
         g.setColor(Color.GREEN)
     elif status == "busy":
         g.setColor(Color.ORANGE)
     elif status == "error":
         g.setColor(Color.BLACK)
     else:
         g.setColor(Color.MAGENTA)
     g.fillOval(3, 3, iconSize - 6, iconSize - 6)
     textLabel = presence.getHost() + ":" + presence.getPort()
     if presence.__name__ != None:
         textLabel = presence.__name__ + " (" + textLabel + ")"
     if self.maxLabelLength > len(textLabel):
         textLabel = textLabel.substring(0, self.maxLabelLength - 3) + "..."
     setIcon(ImageIcon(img))
     setText(textLabel)
     setFont(list_.getFont())
     return self
开发者ID:hobson,项目名称:ggpy,代码行数:42,代码来源:PlayerSelector.py

示例8: RoundedRectangleTool

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
class RoundedRectangleTool(Tool):
    def __init__(self, clientState=None):
        self.client_state = clientState
        self.start_point = None
        self.makeImage()

    def makeImage(self):
        self.image = BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB)
        g = self.image.getGraphics()
        g.setColor(Color(0, 0, 0))
        g.drawRoundRect(0, 0, 31, 31, 10, 10)

    def mousePressed(self, locationOnScreen, g):
        self.start_point = locationOnScreen
        return ""

    def mouseHovered(self, locationOnScreen, g):
        return ""

    def mouseDragged(self, locationOnScreen, g):
        x1 = min(self.start_point.x, locationOnScreen.x)
        y1 = min(self.start_point.y, locationOnScreen.y)
        x2 = max(self.start_point.x, locationOnScreen.x)
        y2 = max(self.start_point.y, locationOnScreen.y)
        g.setColor(self.client_state.selectedColor)
        g.drawRoundRect(x1, y1, x2 - x1, y2 - y1, 20, 20)
        return ""

    def mouseReleased(self, locationOnScreen, g):
        x1 = min(self.start_point.x, locationOnScreen.x)
        y1 = min(self.start_point.y, locationOnScreen.y)
        x2 = max(self.start_point.x, locationOnScreen.x)
        y2 = max(self.start_point.y, locationOnScreen.y)
        return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x1, y1, x2 - x1, y2 - y1)

    def _getmetadata(self):
        return "%d" % self.client_state.selectedColor.getRGB()

    def draw(self, s, g):
        if s == "":
            return
        metadata, points = s.split("|")
        points = points.split(";")
        g.setColor(Color(int(metadata)))
        match = point_re.match(points[0])
        if match is None:
            return
        x1, y1 = match.groups()
        x1, y1 = int(x1), int(y1)
        match = point_re.match(points[1])
        if match is None:
            return
        x2, y2 = match.groups()
        x2, y2 = int(x2), int(y2)
        g.drawRoundRect(x1, y1, x2, y2, 20, 20)

    def getAffectedArea(self, phrase):
        points = phrase.split("|")[1].split(";")
        match = point_re.match(points[0])
        if match is None:
            return
        x1, y1 = match.groups()
        x1, y1 = int(x1), int(y1)
        match = point_re.match(points[1])
        if match is None:
            return
        x2, y2 = match.groups()
        x2, y2 = int(x2), int(y2)
        ax1 = min(x1, x2)
        ay1 = min(y1, y2)
        ax2 = max(x1, x2)
        ay2 = max(y1, y2)
        return [ax1, ay1, ax2 - ax1, ay2 - ay1]

    def getIcon(self):
        return self.image

    def getToolName(self):
        return "Rounded Rectangle"

    def getTooltip(self):
        return "draw a rounded rectangle with one corner\nwhere you click and the opposite\ncorner where you release the mouse"

    def getToolID(self):
        return "roundrect"
开发者ID:rde1024,项目名称:MICT,代码行数:87,代码来源:roundrecttool.py

示例9: _create_buffered_image

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
def _create_buffered_image(image):
    result = BufferedImage(image.getWidth(None),image.getHeight(None),BufferedImage.TYPE_INT_ARGB)
    result.getGraphics().drawImage(image,0,0,None)
    return result
开发者ID:Catrobat,项目名称:ScratchToCatrobat,代码行数:6,代码来源:svgtopng.py

示例10: FilledOvalTool

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
class FilledOvalTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		self.start_point = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.fillOval(0,0,30,30)
	def mousePressed(self, locationOnScreen, g) :
		self.start_point = locationOnScreen
		return ""
	def mouseHovered(self, locationOnScreen, g) :
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		x1 = min(self.start_point.x, locationOnScreen.x)
		y1 = min(self.start_point.y, locationOnScreen.y)
		x2 = max(self.start_point.x, locationOnScreen.x)
		y2 = max(self.start_point.y, locationOnScreen.y)
		g.setColor(self.client_state.selectedColor)		
		g.fillOval(x1, y1, x2 - x1, y2 - y1)
		return ""
	def mouseReleased(self, locationOnScreen, g) :
		x1 = min(self.start_point.x, locationOnScreen.x)
		y1 = min(self.start_point.y, locationOnScreen.y)
		x2 = max(self.start_point.x, locationOnScreen.x)
		y2 = max(self.start_point.y, locationOnScreen.y)
		return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x1, y1, x2 - x1, y2 - y1)		
	def _getmetadata(self) :
		return "%d" % self.client_state.selectedColor.getRGB()
	def draw(self, s, g) :
		if s == "" :
			return
		metadata, points = s.split('|')
		points = points.split(';')
		g.setColor(Color(int(metadata)))
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		g.fillOval(x1, y1, x2, y2)
	def getAffectedArea(self, phrase) :
		points = phrase.split('|')[1].split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		ax1 = min(x1, x2)
		ay1 = min(y1, y2)
		ax2 = max(x1, x2)
		ay2 = max(y1, y2)
		return [ax1, ay1, ax2 - ax1, ay2 - ay1]
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "FilledOval"
	def getTooltip(self) :
		return "draw a Filled Oval inscribed in the imaginary rectagle with one corner\nwhere you click and another\ncorner where you release the mouse"
	def getToolID(self) :
		return 'filledoval'	
开发者ID:bkap,项目名称:MICT,代码行数:75,代码来源:filledovaltool.py

示例11: PencilTool

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
class PencilTool(Tool) :
	def __init__(self, clientState=None) :
		self.client_state = clientState
		self.prev_point_draw = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(209,149,12))
		g.drawLine(20,0,0,25)
		g.drawLine(25,0,5,25)
		g.drawLine(25,0,27,5)
		g.drawLine(20,0,25,0)
		g.drawLine(27,5,8,27)
		g.setColor(Color(0,0,0))
		g.drawLine(0,25,5,32)
		g.drawLine(5,25,5,32)
		g.drawLine(5,25,0,25)
		g.drawLine(8,27,0,25)
		g.drawLine(8,27,5,32)
	def __repr__(self) :
		return self.getToolName()
	def mousePressed(self, locationOnScreen, g) :
		self.prev_point = locationOnScreen
		self.points = [(locationOnScreen.x, locationOnScreen.y)]
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		x0,y0 = self.prev_point.x, self.prev_point.y
		x1,y1 = locationOnScreen.x, locationOnScreen.y
		self.prev_point = locationOnScreen
		return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x0,y0,x1,y1)
	def _getmetadata(self) :
		return "%s" % self.client_state.selectedColor.getRGB()
	def mouseReleased(self, locationOnScreen, g) :
		self.mouseDragged(locationOnScreen, g)
		self.prev_point = None
		return ""
	def draw(self, s, g) :
		if  s == "":
			return
		try :
			metadata, points = s.split('|')
		except ValueError :
			#no metadata given. This is a problem
			return
		points = points.split(';')
		
		#process metadata
		color = int(metadata)
		
		prev_point = None
		
		print "have points"
		g.setColor(Color(color)) 
		for point in points :
			point_match = point_re.match(point)
			if not point_match :
					#this is an error, shouldn't happen. Figure out what to do
					#we were sent bad data
				print "no match"
				return
			x,y = point_match.groups()
			x,y = int(x), int(y)
			if prev_point :
				print "drawing line"
				g.drawLine(prev_point[0], prev_point[1], x, y)
			prev_point = (x,y)
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "Pencil"
	def getTooltip(self) :
		return "Draw wherever the mouse goes"
	def getToolID(self) :
		return "pencil"
	def getAffectedArea(self, phrase) :
		points = phrase.split('|')[1].split(';')
		match = point_re.match(points[0])
		if match is None:
			print "match is none. should not happen. ever."
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			print "match is none. should not happen. ever."
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		ax1 = min(x1, x2)
		ay1 = min(y1, y2)
		ax2 = max(x1, x2)
		ay2 = max(y1, y2)
		return [ax1, ay1 - 1, ax2 - ax1, ay2 - ay1 + 2]
开发者ID:bkap,项目名称:MICT,代码行数:96,代码来源:penciltool.py

示例12: PasteTool

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
class PasteTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		self.start_point = None
		self._image = None
		self.makeImage()
	

	def makeImage(self) :
		#Draw something to indicate copy tool.
		#Currently drawing an X
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.drawLine(3,3,30,3)
		g.drawLine(30,3,30,16)
		g.drawLine(3,3,3,29)
		g.drawLine(3,16,30,16)


	def mousePressed(self, locationOnScreen, g) :
		return ""


	def mouseHovered(self, locationOnScreen, g) :
		return ""


	def mouseDragged(self, locationOnScreen, g) :
		return ""


	def mouseReleased(self, locationOnScreen, g) :
		return ""

	def mouseClicked(self, locationOnScreen, g) :
		if self.client_state.clipboard :
			self._image = ImageData(locationOnScreen.x, locationOnScreen.y, self.client_state.clipboard)
		return ""

	def getLastImage(self) :
		if self._image :
			image = self._image
			self._image = None
			return image
		return None

	def getAffectedArea(self, phrase) :
		# important! 
		return None


	def getIcon(self) :
		return self.image


	def getToolName(self) :
		return "Paste"


	def getTooltip(self) :
		return "Paste the Image stored in memory to the area of the screen clicked on by the mouse."


	def getToolID(self) :
		return 'paste'
开发者ID:bkap,项目名称:MICT,代码行数:68,代码来源:pastetool.py

示例13: CopyTool

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
class CopyTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		if self.client_state is not None :
			self.canvas_image = self.client_state.canvas.getCanvasImage()
		self.start_point = None
		self.makeImage()	
	

	def makeImage(self) :
		#Draw something to indicate copy tool.
		#Currently drawing an X
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.drawLine(7,6,10,3)
		g.drawLine(10,3,22,3)
		g.drawLine(22,3,25,6)
		g.drawLine(7,6,7,26)
		g.drawLine(7,26,10,30)
		g.drawLine(10,30,22,30)
		g.drawLine(22,30,25,27)
		#clear g?


	def mousePressed(self, locationOnScreen, g) :
		self.start_point = locationOnScreen
		return ""


	def mouseHovered(self, locationOnScreen, g) :
		return ""


	def mouseDragged(self, locationOnScreen, g) :
		x1 = self.start_point.x
		y1 = self.start_point.y
		x2 = locationOnScreen.x
		y2 = locationOnScreen.y
		#g.setColor(self.client_state.selectedColor)
		#g.scale(10, 10)
		#g.setStroke(BasicStroke(1.5))
		g.drawRect(x1, y1, x2 - x1, y2 - y1)	#TODO: Ensure this draws to the artifact layer...
		return ""


	def _getmetadata(self) :
		return ""


	def mouseReleased(self, locationOnScreen, g) :
		x1 = self.start_point.x
		y1 = self.start_point.y
		x2 = locationOnScreen.x
		y2 = locationOnScreen.y

		#Save the Image to clipboard.
		dx1 = min(x1, x2)
		dy1 = min(y1, y2)
		dx2 = max(x1, x2)
		dy2 = max(y1, y2)
		img = self.client_state.canvas.getCanvasImage()
		xoff = (img.getWidth(self.client_state.canvas) - self.client_state.canvas.getWidth()) / 2
		yoff = (img.getHeight(self.client_state.canvas) - self.client_state.canvas.getHeight()) / 2
		self.client_state.clipboard = img.getSubimage(dx1+xoff, dy1+yoff, dx2-dx1, dy2-dy1)
		
		return ""


	def draw(self, s, g) :
		if s == "" :
			return
		metadata, points = s.split('|')
		color, size = metadata.split(';')
		color, size = int(color), int(size)
		points = points.split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		g.setColor(Color(color))
		g.drawLine(x1, y1, x2, y2)


	def getAffectedArea(self, phrase) :		#TODO: Determine if this method is necessary
		return None


	def getIcon(self) :
		return self.image


	def getToolName(self) :
		return "Copy"
#.........这里部分代码省略.........
开发者ID:bkap,项目名称:MICT,代码行数:103,代码来源:copytool.py

示例14: LineTool

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
class LineTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		self.start_point = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.drawLine(0,0,32,32)
	def mousePressed(self, locationOnScreen, g) :
		self.start_point = locationOnScreen
		return ""
	def mouseHovered(self, locationOnScreen, g) :
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		x1 = self.start_point.x
		y1 = self.start_point.y
		x2 = locationOnScreen.x
		y2 = locationOnScreen.y
		g.setColor(self.client_state.selectedColor)
		g.drawLine(x1, y1, x2, y2)
		return ""
	def _getmetadata(self) :
		''' gets the color and the thickness (currently hardcoded to 1 since
		that isn't implemented yet'''
		return "%d;%d" % (self.client_state.selectedColor.getRGB(), 1)
	def mouseReleased(self, locationOnScreen, g) :
		x1 = self.start_point.x
		y1 = self.start_point.y
		x2 = locationOnScreen.x
		y2 = locationOnScreen.y
		return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x1, y1, x2, y2)
	def draw(self, s, g) :
		if s == "" :
			return
		metadata, points = s.split('|')
		color, size = metadata.split(';')
		color, size = int(color), int(size)
		points = points.split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		g.setColor(Color(color))
		g.drawLine(x1, y1, x2, y2)
	def getAffectedArea(self, phrase) :
		points = phrase.split('|')[1].split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		ax1 = min(x1, x2)
		ay1 = min(y1, y2)
		ax2 = max(x1, x2)
		ay2 = max(y1, y2)
		return [ax1, ay1, ax2 - ax1, ay2 - ay1]
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "Line"
	def getTooltip(self) :
		return "draw a line from the point where you click to the point where\n you release the mouse"
	def getToolID(self) :
		return 'line'	
开发者ID:bkap,项目名称:MICT,代码行数:79,代码来源:linetool.py

示例15: RectangleTool

# 需要导入模块: from java.awt.image import BufferedImage [as 别名]
# 或者: from java.awt.image.BufferedImage import getGraphics [as 别名]
class RectangleTool(Tool) :
	ICON_SIZE = 32
	ZERO = 0
	THIRTY_ONE = 31
	serialVersionUID = 123456789
	def __init__(self, clientState = None) :
		print type(clientState)
		self.client_state = clientState
		self.start_point = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(self.ICON_SIZE,self.ICON_SIZE,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(self.ZERO,self.ZERO,self.ZERO))
		g.drawRect(self.ZERO,self.ZERO,self.THIRTY_ONE,self.THIRTY_ONE)
	def mousePressed(self, locationOnScreen, g) :
		self.start_point = locationOnScreen
		return ""
	def mouseHovered(self, locationOnScreen, g) :
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		x1 = min(self.start_point.x, locationOnScreen.x)
		y1 = min(self.start_point.y, locationOnScreen.y)
		x2 = max(self.start_point.x, locationOnScreen.x)
		y2 = max(self.start_point.y, locationOnScreen.y)
		g.setColor(self.client_state.selectedColor)
		g.drawRect(x1, y1, x2 - x1, y2 - y1)
		return ""
	def mouseReleased(self, locationOnScreen, g) :
		x1 = min(self.start_point.x, locationOnScreen.x)
		y1 = min(self.start_point.y, locationOnScreen.y)
		x2 = max(self.start_point.x, locationOnScreen.x)
		y2 = max(self.start_point.y, locationOnScreen.y)
		return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x1, y1, x2 - x1, y2 - y1)
	def _getmetadata(self) :
		return "%d" % self.client_state.selectedColor.getRGB()
	def draw(self, s, g) :
		if s == "" :
			return
		metadata, points = s.split('|')
		points = points.split(';')
		g.setColor(Color(int(metadata)))
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		g.drawRect(x1, y1, x2, y2)
	def getAffectedArea(self, phrase) :
		points = phrase.split('|')[1].split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		ax1 = min(x1, x2)
		ay1 = min(y1, y2)
		ax2 = max(x1, x2)
		ay2 = max(y1, y2)
		return [ax1, ay1, ax2 - ax1, ay2 - ay1]
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "Rectangle"
	def getTooltip(self) :
		return "draw a rectangle with one corner\nwhere you click and the opposite\ncorner where you release the mouse"
	def getToolID(self) :
		return 'rect'   
开发者ID:bkap,项目名称:MICT,代码行数:80,代码来源:rectangletool.py


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