UIImageのマゼンタ部分をクリアして透明にするにはどうすればよいですか?UIImageでiOSカラーを透明にする
多くの回答とリンクを調べています(例:How to make one color transparent on a UIImage?答え1は、赤以外のすべてを削除します。回答2は、Why is CGImageCreateWithMaskingColors() returning nil in this case?のために動作しません)。
更新:
私はUIImageでCGImageCreateWithMaskingColorsを使用している場合は、私がnil値を取得します。 CGImageCreateWithMaskingColors(CGImageCreateWithMaskingColors)は、アルファチャンネルを取り除くと(JPEGとしてイメージを表し、それを読み戻す)、黒い背景で描画されたイメージを返します。
アップデート2、コード:
戻っゼロ:
UIImage *inputImage = [UIImage imageWithData:UIImageJPEGRepresentation(anchorWithMask, 1.0)];
const float colorMasking[6] = {222, 255, 222, 255, 222, 255};
CGImageRef imageRef = CGImageCreateWithMaskingColors(inputImage.CGImage, colorMasking);
NSLog(@"image ref %@", imageRef);
// imgref is NOT nil.
UIImage *image = [UIImage imageWithCGImage:imageRef];
:
const float colorMasking[6] = {222, 255, 222, 255, 222, 255};
CGImageRef imageRef = CGImageCreateWithMaskingColors(anchorWithMask.CGImage, colorMasking);
NSLog(@"image ref %@", imageRef);
// this is going to return a nil imgref.
UIImage *image = [UIImage imageWithCGImage:imageRef];
(アルファチャンネルが存在しないので、正常である)黒い背景の画像を返します更新3:
私はマスキングプロセスの後にアルファチャンネルを追加して動作させました。
あなたのコードを投稿してください。 –
コードを追加しました。 –