本文整理汇总了Python中Image.Image.x方法的典型用法代码示例。如果您正苦于以下问题:Python Image.x方法的具体用法?Python Image.x怎么用?Python Image.x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image.Image
的用法示例。
在下文中一共展示了Image.x方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImageView
# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import x [as 别名]
class ImageView(QtGui.QScrollArea):
def __init__(self,parent):
'''constructor of ImageView'''
QtGui.QWidget.__init__(self)
self.parent = parent
self.selection = None
self.image = None
self.zoom = 100
#if (!ic) ic=new IconCache();
self.setFocusPolicy(QtCore.Qt.WheelFocus)
self.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
self.d =ImageViewPrivate(self)
self.setWidget(self.d)
self.setWidgetResizable(True)
self.setBackgroundRole(QtGui.QPalette.Dark)
self.setMouseTracking(True)
self.mouse_x = -1
self.mouse_y = -1
self.mouse_ex = 0
self.mouse_ey = 0
self.data_rect = QtCore.QRect(0,0,1,1)
#self.setMode(view)
def saveImage(self,name):
'''Save image in viewer under given name'''
if self.image:
save_success = self.image.saveImage(name)
if save_success:
return True
else :
return False
else:
print("[ImageView][Save Image Failed]:No image to save")
return False
def selectionFromImageCoords(self,selectionRect):
'''Return selection rectangle converted from image coordinate system to window coordinate syste'''
x= (selectionRect.left())*self.data_rect.width()/self.image.x()+self.data_rect.left()
y= (selectionRect.top())*self.data_rect.height()/self.image.y()+self.data_rect.top()
xr=(selectionRect.right()+1)*self.data_rect.width()/self.image.x()+self.data_rect.left()-1
yr=(selectionRect.bottom()+1)*self.data_rect.height()/self.image.y()+self.data_rect.top()-1
return QRect(x,y,xr,yr)
def selectPointToImageCoords(self,point):
'''Return selected point converted to image coordinate system'''
dw=self.data_rect.width()
dh=self.data_rect.height()
x=int(floor((point.x()-self.data_rect.left())* self.image.x()/dw))-1
y=int(floor((point.y()-self.data_rect.top())* self.image.y()/dh))-1
return QPoint(x,y)
def selectionToImageCoords(self,selectionRect):
'''Return selection rectangle converted to image coordinate [email protected] selectionRect rectangle to convert'''
dw=self.data_rect.width()
dh=self.data_rect.height()
x=int(floor((selectionRect.left()-self.data_rect.left())* self.image.x()/dw))
y=int(floor((selectionRect.top()-self.data_rect.top())* self.image.y()/dh))
xr=int(floor((selectionRect.right()-self.data_rect.left()) * self.image.x()/dw))
yr=int(floor((selectionRect.bottom()-self.data_rect.top())*self.image.y()/dh))
#print(QRect(x,y,xr,yr))
return QRect(x,y,xr,yr)
def setDataRect(self):
'''Update data_rect'''
#Get image dimensions
dx=self.image.x()
dy=self.image.y()
if dx == 0 or dy == 0:
print("Null Image")
return
#printInfo ="setDataRect %f_%f" %(dx,dy)
#print(printInfo)
#Get image screen dimensions (may differ if zoom is set)
screen_dx=dx*self.zoom/100.0
screen_dy=dy*self.zoom/100.0
x=self.d.width()
y=self.d.height()
wx=x
wy=dy*wx/dx
if wy > y:
wy=y
wx=dx*wy/dy
if self.isSet("center"):#居中画图而不拉伸
self.data_rect=QRect(max((x-screen_dx)/2,0),max((y-screen_dy)/2,0),screen_dx,screen_dy)
else:
self.data_rect=QRect(max((x-wx)/2,0),max((y-wy)/2,0),wx,wy)
def getSelection(self):
'''return the selection rectangle from (x0,y0,x1,y1) to (x,y,width,height)'''
if not self.selection:
return None
width = self.selection.width() - self.selection.left()
height = self.selection.height() - self.selection.top()
return QRect(self.selection.left(),self.selection.top(),width,height)
def repaint(self,x,y,p,src):
'''Repaint the image using given painter and size of output window
@param x width of output window
@param y height of output window
@param p QPainter to use
#.........这里部分代码省略.........