CGImage를 가져 와서 픽셀을 반복하고 알파 값을 변경하고 싶습니다.CGImage에서 픽셀의 알파를 편집하는 방법
이 스레드와 같이 픽셀의 RGB 값을 변경하는 코드를 보았습니다. Is programmatically inverting the colors of an image possible? 픽셀의 RGB 값을 반전하는 방법을 보여줍니다.
하지만 알파 값을 변경하고 싶습니다.
이렇게 할 방법이 있습니까?
CGImage를 가져 와서 픽셀을 반복하고 알파 값을 변경하고 싶습니다.CGImage에서 픽셀의 알파를 편집하는 방법
이 스레드와 같이 픽셀의 RGB 값을 변경하는 코드를 보았습니다. Is programmatically inverting the colors of an image possible? 픽셀의 RGB 값을 반전하는 방법을 보여줍니다.
하지만 알파 값을 변경하고 싶습니다.
이렇게 할 방법이 있습니까?
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)];
}
이미지에는 앱에서 액세스 할 수있는 픽셀 또는 알려진 크기의 픽셀이 있거나 없을 수 있습니다. 그러나 이미지를 생성 한 비트 맵에 렌더링 할 수 있습니다. RGBA (또는 ABGR) 비트 맵인 경우 RGB 값을 변경할 수있는 것과 동일한 방식으로 모든 픽셀의 알파를 변경할 수 있습니다. 앱은이 수정 된 비트 맵에서 새 이미지를 만들 수 있습니다.