2 つの UIImageViews があり、画像を一方から他方にコピーして色を調整したいのですが、奇妙なストレッチが発生しています。
コピーを作成するために使用するコードは次のとおりです。
_selectedIcon.image = groupView.icon;
[ViewUtils colorImageView:_selectedIcon withRed:0.843 Green:0.3176 andBlue:0.066667];
最初の行のみを使用すると、画像が正常にコピーされ、次のようになります。
強調表示するためのものなので、少し大きくなっています。ただし、コピーして正しくスケーリングします。次に、色を付けようとすると、次のようになります。
画像に色を付けるために使用するコードは次のとおりです。
+(void)colorImageView:(UIImageView*)source withRed:(CGFloat)red Green:(float)green andBlue:(float)blue
{
// Create a context containing the image.
UIGraphicsBeginImageContext(source.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
// The mask needs to be upside down for some reason
CGContextTranslateCTM(context, 0, source.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextClipToMask(context, source.bounds, [source.image CGImage]);
CGContextFillRect(context, source.bounds);
[[UIColor colorWithRed:red green:green blue:blue alpha:1.0] set];
UIBezierPath *imagePath = [UIBezierPath bezierPathWithRect:source.bounds];
[imagePath fill];
// Retrieve the new image.
source.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
着色コードで画像をスケーリングするさまざまな方法を試しましたが、何も機能しないようです。誰か提案がありますか?