我需要拍摄图像的中心部分并缩放它,保持原始图像的相同尺寸。 我已经能够缩放图像的一部分保持相同的图像尺寸,但我不明白,因为这部分不是中心部分。
这是代码:
def zoom(source,x):
#@param source:Picture;
#@param x:int; the value to scale up the image;
target=makeEmptyPicture(getWidth(source),getHeight(source))
width=getWidth(source)
height=getHeight(source)
Xseq = []
Yseq = []
colCentrale=x/2 #central column
rigCentrale=x/2 #central row
Xseq = []
for sourceX in range(colCentrale*(width/x),(colCentrale*(width/x))+(width/x)):
for n in range(0,x):
Xseq = Xseq+[sourceX]
Yseq = []
for sourceY in range(rigCentrale*(height/x),(rigCentrale*(height/x))+(height/x)):
for m in range(0,x):
Yseq = Yseq+[sourceY]
targetX=0
for sourceX in Xseq:
targetY=0
for sourceY in Yseq:
color = getColor(getPixel(source,sourceX,sourceY))
setColor(getPixel(target,targetX,targetY),color)
targetY = targetY + 1
targetX = targetX + 1
show(target)