我在使用 GPUImage 变换过滤器时遇到问题。我正在使用平移手势识别器来重新定位图像。我的代码有效,但图像以大约一半的速度移动。如果我CGAffineTransform newTransform
将坐标加倍,图像会按预期拖动。但是,当我开始一个新的平移手势时,图像会跳到距离中心大约两倍的点。也许我的数学是错误的。有任何想法吗?或者,任何人都可以提出比我这里更好的解决方案吗?
- (void)move:(UIPanGestureRecognizer *)sender {
// Translated CGPoint from GPUImageView
CGPoint translation = [sender translationInView:self.primaryImageView];
// Current transform from GPUImageTransformFilter
CGAffineTransform currentTransform = self.transFilter.affineTransform;
// Size of GPUImageView bounds for later calculations
CGSize size = self.primaryImageView.bounds.size;
if ([sender state] == UIGestureRecognizerStateBegan) {
// Set a beginning CGPoint
// Multiply GPUImageView bounds by current transform to get
// the translated coordinates in pixels.
self.beginPoint = CGPointMake(size.width*currentTransform.tx, size.height*currentTransform.ty);
}
// Calculate difference from beginning point to translated point
CGPoint updatedPoint = CGPointMake(self.beginPoint.x+translation.x, self.beginPoint.y+translation.y);
// Create a new transform translation.
// Divide updated coordinates by GPUImageView bounds to get
// a percentage value (-1 to 1)
CGAffineTransform newTransform = CGAffineTransformMakeTranslation(updatedPoint.x/(size.width), updatedPoint.y/(size.height));
// Apply new transform to filter and process.
[self.transFilter setAffineTransform:newTransform];
[self.sourcePicture processImage];
}