2011-12-11 23 views

回答

1

您可以使用color picker中的代碼獲取圖像的RGBA矩陣並更改alpha。並保存到圖像回來。

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值一樣更改任何像素的Alpha。你的應用可以從這個修改的位圖創建一個新的圖像。