2011-12-11 4 views
0

CGImageを使ってピクセルを繰り返し、アルファ値を変更したいと考えています。CGImageでピクセルのアルファを編集するには

このスレッドのように、ピクセルのRGB値を変更するコードがあります。Is programmatically inverting the colors of an image possible? ピクセルのRGB値を反転する方法を示します。

しかし、私はアルファ値を変更したいと思います。

これを行う方法はありますか?

答えて

1

color pickerのコードを使用すると、画像のRGBAマトリックスを取得してアルファを変更できます。イメージを元に戻す。

https://github.com/sakrist/VBColorPicker/blob/master/VBColorPicker/VBColorPicker.m

unsigned char* data = CGBitmapContextGetData (cgctx); 
if (data != NULL && data != 0) { 
    //offset locates the pixel in the data from x,y. 
    //4 for 4 bytes of data per pixel, w is width of one row of data. 
    int offset = 4*((w*round(point.y))+round(point.x)); 
    int alpha = data[offset]; 
    int red = data[offset+1]; 
    int green = data[offset+2]; 
    int blue = data[offset+3]; 
    NSLog(@"offset: %i colors: RGB A %i %i %i %i",offset,red,green,blue,alpha); 
    color = [UIColor colorWithRed:(red/255.0f) green:(green/255.0f) blue:(blue/255.0f) alpha:(alpha/255.0f)]; 
} 
0

画像には、アプリがアクセス可能なピクセルまたは既知のサイズのピクセルがある場合とない場合があります。ただし、作成したビットマップにイメージをレンダリングすることはできます。 RGBA(またはABGR)ビットマップの場合は、RGB値を変更するのと同じ方法で、任意のピクセルのアルファ値を変更できます。あなたのアプリは、この変更されたビットマップから新しいイメージを作成できます。

関連する問題