Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在图像的透明区域添加Imageview_Ios_Iphone_Image_Image Processing_Uiimageview - Fatal编程技术网

Ios 如何在图像的透明区域添加Imageview

Ios 如何在图像的透明区域添加Imageview,ios,iphone,image,image-processing,uiimageview,Ios,Iphone,Image,Image Processing,Uiimageview,我正在开发彩色相框应用程序,但我被困在一个部分。我的应用程序中有很多框架。所以我想找到我的应用程序的透明区域,并以编程方式将UIImageView放在该部分。但我尝试了大量的代码来逐像素读取,还有更多的代码,但都不起作用 下面是我用来查找透明区域的代码 CGImageRef imageRef = [image CGImage]; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char *rawDat

我正在开发彩色相框应用程序,但我被困在一个部分。我的应用程序中有很多框架。所以我想找到我的应用程序的透明区域,并以编程方式将UIImageView放在该部分。但我尝试了大量的代码来逐像素读取,还有更多的代码,但都不起作用

下面是我用来查找透明区域的代码

CGImageRef imageRef = [image CGImage];

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

unsigned char *rawData = malloc(image.size.width * image.size.height * 4);

NSUInteger bytesPerPixel = 4;

NSUInteger bytesPerRow = bytesPerPixel * image.size.width;

NSUInteger bitsPerComponent = 8;

CGContextRef context = CGBitmapContextCreate(rawData, image.size.width, image.size.height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

CGColorSpaceRelease(colorSpace);

CGContextDrawImage(context, CGRectMake(0, 0, image.size.width , image.size.height), imageRef);

CGContextRelease(context);

unsigned char * rawData2 = malloc(image.size.width * image.size.height * 4);

BOOL isBlank = YES;

for(int index=0;index<(image.size.width * image.size.height * 4);index+=4)
{
    if(index%4==0)
    {
        if(rawData[(int)index+3]==0)
        {
            rawData2[(int)index]   = rawData[(int)index];
            rawData2[(int)index+1] = rawData[(int)index+1];
            rawData2[(int)index+2] = rawData[(int)index+2];
            rawData2[(int)index+3] = rawData[(int)index+3];
            isBlank=NO;
        }
        else
        {

            rawData2[(int)index]   = 0;
            rawData2[(int)index+1] = 0;
            rawData2[(int)index+2] = 0;
            rawData2[(int)index+3] = 0;
        }
    }
}
CGImageRef imageRef=[image CGImage];
CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB();
无符号字符*rawData=malloc(image.size.width*image.size.height*4);
NSU整数字节/像素=4;
NSUInteger bytesPerRow=bytesPerPixel*image.size.width;
NSU整数比特分量=8;
CGContextRef context=CGBitmapContextCreate(原始数据、image.size.width、image.size.height、bitsPerComponent、bytesPerRow、颜色空间、KCGimageAlphaPremultipledLast | kCGBitmapByteOrder32Big);
CGCOLORSPACTERELEASE(色彩空间);
CGContextDrawImage(上下文,CGRectMake(0,0,image.size.width,image.size.height),imageRef);
CGContextRelease(上下文);
unsigned char*rawData2=malloc(image.size.width*image.size.height*4);
BOOL isBlank=是;

对于(int index=0;indexi)如果逐像素读取,肯定会得到每个像素的矩形,每个像素具有rgba(0,0,0,0)值我认为您需要计算主imageview的坐标和像素,然后将子imageview添加到透明位置。是的,我尝试获取每4个像素并搜索透明区域,但有5个区域,因此如何从像素中找到cgrect您是否在运行时获得部分透明图像?如果在Storyboard/Xib中设置,您可以不要在位置中添加空图像视图,只需用图像填充即可。感谢回复@Evgeniy请检查此图像