1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 照片直播 php php直播源码 iOS 图片去背景

照片直播 php php直播源码 iOS 图片去背景

时间:2022-11-09 02:16:09

相关推荐

照片直播 php php直播源码 iOS 图片去背景

php直播源码,iOS 图片去背景相关的代码

-(UIImage*)removeBackgroudWithImage:(UIImage*)image{

unsignedchar*targetData=malloc(sizeof(unsignedchar)*image.size.width*image.size.height*4);

UIGraphicsBeginImageContext(image.size);

[imagedrawInRect:CGRectMake(0,0,image.size.width,image.size.height)];

unsignedchar*data=malloc(sizeof(unsignedchar)*image.size.width*image.size.height*4);

[selfimageRGBABytesRef:&dataFromImage:image];

for(inti=0;i

UIColor*pixleColor=[UIColorcolorWithRed:data[i]/255.0green:data[i+1]/255.0blue:data[i+2]/255.0alpha:data[i+3]/255.0];

CGFloatc,m,y,k,a;

[pixleColorgetCyan:&cmagenta:&myellow:&yblack:&kalpha:&a];//YYKit中的类别方法

targetData[i]=data[i];

targetData[i+1]=data[i+1];

targetData[i+2]=data[i+2];

if(k

targetData[i+3]=0;

}else{

targetData[i+3]=255;

}

}

UIImage*result=[selfimageFromBRGABytes:targetDataimageSize:image.size];

free(targetData);

returnresult;

}

-(UIImage*)imageFromBRGABytes:(unsignedchar*)imageBytesimageSize:(CGSize)imageSize{

CGImageRefimageRef=[selfimageRefFromBGRABytes:imageBytesimageSize:imageSize];

UIImage*image=[UIImageimageWithCGImage:imageRef];

CGImageRelease(imageRef);

returnimage;

}

-(CGImageRef)imageRefFromBGRABytes:(unsignedchar*)imageBytesimageSize:(CGSize)imageSize{

CGColorSpaceRefcolorSpace=CGColorSpaceCreateDeviceRGB();

CGContextRefcontext=CGBitmapContextCreate(imageBytes,

imageSize.width,

imageSize.height,

8,

imageSize.width*4,

colorSpace,

kCGImageAlphaPremultipliedLast);

CGImageRefimageRef=CGBitmapContextCreateImage(context);

CGContextRelease(context);

CGColorSpaceRelease(colorSpace);

returnimageRef;

}

-(void)imageRGBABytesRef:(unsignedchar**)dataFromImage:(UIImage*)image{

unsignedchar*targetData=malloc(sizeof(unsignedchar)*image.size.width*image.size.height*4);

CGColorSpaceRefcolorSpace=CGColorSpaceCreateDeviceRGB();

CGContextRefcontext=CGBitmapContextCreate(targetData,

image.size.width,

image.size.height,

8,

image.size.width*4,

colorSpace,

kCGImageAlphaPremultipliedLast);

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

memcpy(*data,targetData,sizeof(unsignedchar)*image.size.width*image.size.height*4);

CGContextRelease(context);

CGColorSpaceRelease(colorSpace);

}

以上就是

php直播源码,iOS 图片去背景相关的代码,更多内容欢迎关注之后的文章

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。