0
那裏。我怎樣才能從另一個ViewController chage CGImageRef?CGImageRef更改
我有這樣的代碼:
#import "ScratchableView.h"
@implementation ScratchableView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
//init with the scratchable gray image
scratchable = [UIImage imageNamed:@"image.jpg"].CGImage;
width = CGImageGetWidth(scratchable);
height = CGImageGetHeight(scratchable);
self.opaque = NO;
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
CFMutableDataRef pixels = CFDataCreateMutable(NULL , width * height);
alphaPixels = CGBitmapContextCreate(CFDataGetMutableBytePtr(pixels) , width , height , 8 , width , colorspace , kCGImageAlphaNone);
provider = CGDataProviderCreateWithCFData(pixels);
CGContextSetFillColorWithColor(alphaPixels, [UIColor blackColor].CGColor);
CGContextFillRect(alphaPixels, frame);
CGContextSetStrokeColorWithColor(alphaPixels, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(alphaPixels, 30.0);
CGContextSetLineCap(alphaPixels, kCGLineCapSquare);
CGImageRef mask = CGImageMaskCreate(width, height, 8, 8, width, provider, nil, NO);
scratched = CGImageCreateWithMask(scratchable, mask);
CGImageRelease(mask);
CGColorSpaceRelease(colorspace);
}
return self;
}
現在從另一個視圖控制器我想改變與image2.jpg的image.jpg的。請幫助我,我該怎麼做?
我嘗試使用應用程序委託,與nsstrings,但沒有成功。我是初學者。
如何'ScratchableView'聲明?它是從哪裏繼承的?你如何顯示'image.jpg'? – user1118321
- (void)awakeFromNib { //使用劃痕圖像添加劃痕視圖 scratchableView = [[ScratchableView alloc] initWithFrame:self.frame]; \t [self addSubview:scratchableView]; backimg = [NSString stringWithFormat:@「backgr1.jpg」]; //在劃痕圖像下添加另一個圖像。 UIImageView * background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:backimg]];}};}}; \t [self addSubview:background]; \t [self bringSubviewToFront:scratchableView]; } – user1625435
我有github的CGScratch項目,我想刷一下,或搖晃來改變這兩個圖像,你能幫助我嗎.. – user1625435