我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用Image.ROTATE_90。
def getmask2(self, text, mode="", fill=Image.core.fill): size, offset = self.font.getsize(text) im = fill("L", size, 0) self.font.render(text, im.id, mode=="1") return im, offset ## # Wrapper that creates a transposed font from any existing font # object. # # @param font A font object. # @param orientation An optional orientation. If given, this should # be one of Image.FLIP_LEFT_RIGHT, Image.FLIP_TOP_BOTTOM, # Image.ROTATE_90, Image.ROTATE_180, or Image.ROTATE_270.
def getsize(self, text): w, h = self.font.getsize(text) if self.orientation in (Image.ROTATE_90, Image.ROTATE_270): return h, w return w, h
def draw_rotated_text(self, image, text, position, angle, font, fill=(255,255,255), display = True): draw = ImageDraw.Draw(image) width, height = draw.textsize(text, font=font) textimage = Image.new('RGBA', (width, height), (0,0,0,0)) textdraw = ImageDraw.Draw(textimage) textdraw.text((0,0), text, font=font, fill=fill) if angle == - 90: textimage = textimage.transpose(Image.ROTATE_270) if angle == -180: textimage = textimage.transpose(Image.ROTATE_180) if angle == -270: textimage = textimage.transpose(Image.ROTATE_90) image.paste(textimage, position, textimage) if(display): self.disp.display() ## Determines the width of the screen based on rotation (Experienced users) # @param self The object pointer.
def fillImgArray(self, x, y, width, height, image, display = True): buff = self.disp.buffer actx = self.screenXFromImageCoords(x,y) acty = self.screenYFromImageCoords(x,y) image = Image.fromarray(image) image = image.resize((width,height), Image.ANTIALIAS) cr = self.currentRotation if(cr == 1): actx -= height image = image.transpose(Image.ROTATE_270) if(cr == 2): acty -= height actx -= width image = image.transpose(Image.ROTATE_180) if(cr == 3): acty -= width image = image.transpose(Image.ROTATE_90) buff.paste(image, (actx,acty)) if(display): self.disp.display() ## Rotates the screen orientation 90 degrees to the right (-90 degrees) # @param self The object pointer. # @remark # To use this function in your program: # @code # ... # screen.rotateRight() # @endcode
def fillBmp(self, x, y, width, height, path = "/usr/local/mindsensors/images/Pane1.png", display = True): buff = self.disp.buffer actx = self.screenXFromImageCoords(x,y) acty = self.screenYFromImageCoords(x,y) # if the caller only provided icon name, assume it is in our system repository if (path[0] != "/"): path = "/usr/local/mindsensors/images/" + path # if the image is missing, use a default X image. if (os.path.isfile(path)): image = Image.open(path) else: image = Image.open("/usr/local/mindsensors/images/missing.png") image = image.resize((width,height), Image.ANTIALIAS) cr = self.currentRotation if(cr == 1): actx -= height image = image.transpose(Image.ROTATE_270) if(cr == 2): acty -= height actx -= width image = image.transpose(Image.ROTATE_180) if(cr == 3): acty -= width image = image.transpose(Image.ROTATE_90) buff.paste(image, (actx,acty)) if(display): self.disp.display() ## Draw a image on the screen using supplied image data # @param self The object pointer. # @param x The upper left x coordinate of the image. # @param y The upper left y coordinate of the image. # @param width The width of the image. # @param height The width of the image. # @param image data # @param display Choose to immediately push the drawing to the screen. Optional, defaults to True. # @remark # To use this function in your program: # @code # ... # screen.screen.fillBmp(40, 0, 240, 240, image) # @endcode