Beispiel #1
0
def getcolor(style, alpha=None):
    if style is None:
        return None
        
    if isinstance(style, Color):
        c = style
        if not alpha is None:
            alpha = (int)(alpha * 255)
            c = Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)
        return c
        
    c = Color.black
    if isinstance(style, str):
        if style == 'red':
            c = Color.red
        elif style == 'black':
            c = Color.black
        elif style == 'blue':
            c = Color.blue
        elif style == 'green':
            c = Color.green
        elif style == 'white':
            c = Color.white
        elif style == 'yellow':
            c = Color.yellow
        elif style == 'gray':
            c = Color.gray
        elif style == 'lightgray':
            c = Color.lightGray
        else:
            if 'r' in style:
                c = Color.red
            elif 'k' in style:
                c = Color.black
            elif 'b' in style:
                c = Color.blue
            elif 'g' in style:
                c = Color.green
            elif 'w' in style:
                c = Color.white
            elif 'c' in style:
                c = Color.cyan
            elif 'm' in style:
                c = Color.magenta
            elif 'y' in style:
                c = Color.yellow 
    elif isinstance(style, (tuple, list)):
        if len(style) == 3:
            c = Color(style[0], style[1], style[2])
        else:
            c = Color(style[0], style[1], style[2], style[3])
    
    if not alpha is None:
        alpha = (int)(alpha * 255)
        c = Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)
    
    return c
Beispiel #2
0
def getcolor(style, alpha=None):
    if style is None:
        return None
        
    if isinstance(style, Color):
        c = style
        if not alpha is None:
            alpha = (int)(alpha * 255)
            c = Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)
        return c
        
    c = Color.black
    if isinstance(style, str):
        if style == 'red' or style == 'r':
            c = Color.red
        elif style == 'black' or style == 'k':
            c = Color.black
        elif style == 'blue' or style == 'b':
            c = Color.blue
        elif style == 'green' or style == 'g':
            c = Color.green
        elif style == 'white' or style == 'w':
            c = Color.white
        elif style == 'yellow' or style == 'y':
            c = Color.yellow
        elif style == 'gray':
            c = Color.gray
        elif style == 'lightgray':
            c = Color.lightGray
        elif style == 'cyan' or style == 'c':
            c = Color.cyan
        elif style == 'magenta' or style == 'm':
            c = Color.magenta
        elif style == 'pink' or style == 'p':
            c = Color.pink
        else:
            try:
                c = Color.decode(style)
            except:
                c = None
                print('Not a valid color: {}'.format(style))
                return c
    elif isinstance(style, (tuple, list)):
        if len(style) == 3:
            c = Color(style[0], style[1], style[2])
        else:
            c = Color(style[0], style[1], style[2], style[3])
    
    if not alpha is None:
        alpha = (int)(alpha * 255)
        c = Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)
    
    return c
    def read(self, filename):
        """Read an image from a .png, .gif, or .jpg file. as 2D list of RGB pixels."""

        # JEM working directory fix (see above)
        filename = fixWorkingDirForJEM(filename)  # does nothing if not in JEM

        # ***
        #print "fixWorkingDirForJEM( filename ) =", filename

        file = File(filename)  # read file from current directory
        self.image = ImageIO.read(file)
        self.width = self.image.getWidth(None)
        self.height = self.image.getHeight(None)

        pixels = []  # initialize list of pixels

        # load pixels from image
        for row in range(self.height):
            pixels.append([])  # add another empty row
            for col in range(self.width):  # now, populate row with pixels
                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, pixels have been loaded from image file, so create an image
        self.setPixels(pixels)
Beispiel #4
0
   def read(self, filename): 
      """Read an image from a .png, .gif, or .jpg file. as 2D list of RGB pixels."""
      
      # JEM working directory fix (see above)
      filename = fixWorkingDirForJEM( filename )   # does nothing if not in JEM
	  
      # ***
      #print "fixWorkingDirForJEM( filename ) =", filename

      file = File(filename)    # read file from current directory
      self.image = ImageIO.read(file)
      self.width  = self.image.getWidth(None)
      self.height = self.image.getHeight(None)
      
      pixels = []   # initialize list of pixels
      
      # load pixels from image
      for row in range(self.height):
         pixels.append( [] )   # add another empty row
         for col in range(self.width):   # now, populate row with pixels
            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, pixels have been loaded from image file, so create an image
      self.setPixels(pixels)
Beispiel #5
0
   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)
Beispiel #6
0
 def get_at(self, pos):
     """
     Return color of a surface pixel.
     The pos argument represents x,y position of pixel.
     """
     x,y = pos       #*tuple unpack error in jython applet
     try:
         color = Color(self.getRGB(x,y))
     except:     #ArrayOutOfBoundsException
         raise IndexError
     return color.getRed(), color.getGreen(), color.getBlue()
Beispiel #7
0
 def get_at(self, pos):
     """
     Return color of a surface pixel.
     The pos argument represents x,y position of pixel.
     """
     x, y = pos  #*tuple unpack error in jython applet
     try:
         color = Color(self.getRGB(x, y))
     except:  #ArrayOutOfBoundsException
         raise IndexError
     return color.getRed(), color.getGreen(), color.getBlue()
Beispiel #8
0
   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 getGUI(sym_dict):
	global frame, outCheckbox, fillCheckbox, slider, colorTF, widthTF
	frame = JFrame("Border Symbology", defaultCloseOperation=JFrame.DISPOSE_ON_CLOSE, 
		       bounds=(100, 100, 450, 200), layout=FlowLayout(), resizable=0)

	colorL = JLabel('Color: ')
	colorTF = JTextField(20)
	color = sym_dict["color"]
	color = Color(color.getRed(), color.getGreen(), color.getBlue(), sym_dict["alpha"])
	colorTF.setBackground(color)
	colorTF.setText(color.toString())

	colorB = JButton('...', actionPerformed=colorChooser)
	frame.add(colorL)
	frame.add(colorTF)
	frame.add(colorB)

	widthL = JLabel('Width: ')
	widthTF = JTextField(3)
	widthTF.setText(str(sym_dict["width"]))
	frame.add(widthL)
	frame.add(widthTF)

	alphaL = JLabel('Transparency: ')
	frame.add(alphaL)

	# Create a horizontal slider with min=0, max=100, value=50
	slider = JSlider()
	slider.setPreferredSize(Dimension(200, 50))
	slider.setValue(sym_dict["alpha"]*100/255)
	slider.setMajorTickSpacing(25)
	slider.setMinorTickSpacing(5)
	slider.setPaintTicks(1)
	slider.setPaintLabels(1)

	applyButton = JButton("Apply", actionPerformed=action)
	acceptButton = JButton("Accept", actionPerformed=accept)

	frame.add(slider)
	frame.add(applyButton)
	frame.add(acceptButton)

	frame.show()
Beispiel #10
0
#!/usr/bin/env python
# vim: set fileencoding=utf-8

from java.awt import Color
from java.lang import StringBuffer
from java.awt import Button

color = Color(0.5, 1.0, 0.0)

print("\nRed")
print(color.getRed())
print(color.red)

print("\nGreen")
print(color.getGreen())
print(color.green)

print("\nBlue")
print(color.getBlue())
print(color.blue)

print("\nTransparency")
print(color.getTransparency())
print(color.transparency)
Beispiel #11
0
from java.awt import Color

print("red")

c = Color(1, 0, 0)

print(c.getRed())
print(c.getGreen())
print(c.getBlue())
print(c.getAlpha())

print("")

print(c.red)
print(c.green)
print(c.blue)
print(c.alpha)

print("\n\nyellow")

c2 = Color.YELLOW

print(c2.red)
print(c2.green)
print(c2.blue)
print(c2.alpha)
Beispiel #12
0
def getListColor(SCREEN):  #pass a Region and get pixel (r,g,b)
    i = Robot().createScreenCapture(
        Rectangle(SCREEN.getX(), SCREEN.getY(), SCREEN.getW(), SCREEN.getH()))

    c = Color(i.getRGB(0, 0))
    return c.getRed(), c.getGreen(), c.getBlue()