Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>//Create our colorspaces imageColorSpace = CGColorSpaceCreateDeviceRGB(); maskColorSpace = CGColorSpaceCreateDeviceGray(); provider=CGDataProviderCreateWithCFData((__bridge CFDataRef)self.puzzleData); image=CGImageCreateWithPNGDataProvider(provider, NULL, true, kCGRenderingIntentDefault); CGDataProviderRelease(provider); //Resize the puzzle image context = CGBitmapContextCreate(NULL, kPuzzleSize, kPuzzleSize, 8, 0, imageColorSpace, kCGImageAlphaPremultipliedFirst); CGContextDrawImage(context, CGRectMake(0, 0, kPuzzleSize, kPuzzleSize), image); CGImageRelease(image); image = CGBitmapContextCreateImage(context); CGContextRelease(context); //Create the image view with the puzzle image self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kPuzzleSize, kPuzzleSize)]; [self.imageView setImage:[UIImage imageWithCGImage:image]]; //Create the puzzle pieces (note that pieces are rotated to the puzzle orientation in order to minimize the number of graphic operations when creating the puzzle images) for(i = 0; i &lt; appDelegate().puzzleSize * appDelegate().puzzleSize; ++i) { //Recreate the piece view [pieces[i] removeFromSuperview]; pieces[i] = [[CJPieceView alloc] initWithFrame:CGRectMake(0, 0, kPieceSize, kPieceSize) index:i]; [pieces[i] setTag:-1]; //Load puzzle piece mask image UIImage *maskimage=[self.arrmaskImages objectAtIndex:i]; NSData *dataMaskImage=UIImagePNGRepresentation(maskimage); provider=CGDataProviderCreateWithCFData((__bridge CFDataRef)dataMaskImage); tile = CGImageCreateWithPNGDataProvider(provider, NULL, true, kCGRenderingIntentDefault); CGDataProviderRelease(provider); mask = CGImageCreateCopyWithColorSpace(tile, maskColorSpace); CGImageRelease(tile); context = CGBitmapContextCreate(NULL, kPieceSize / kPieceShadowFactor, kPieceSize / kPieceShadowFactor, 8, 0, imageColorSpace, kCGImageAlphaPremultipliedFirst); CGContextClipToMask(context, CGRectMake(0, 0, kPieceSize / kPieceShadowFactor, kPieceSize / kPieceShadowFactor), mask); CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0); CGContextFillRect(context, CGRectMake(0, 0, kPieceSize / kPieceShadowFactor, kPieceSize / kPieceShadowFactor)); shadow = CGBitmapContextCreateImage(context); CGContextRelease(context); imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kPieceSize, kPieceSize)]; [imageView setImage:[UIImage imageWithCGImage:shadow]]; [imageView setAlpha:kPieceShadowOpacity]; [imageView setUserInteractionEnabled:NO]; [pieces[i] addSubview:imageView]; CGImageRelease(shadow); //Create image view with piece image and add it to the piece view context = CGBitmapContextCreate(NULL, kPieceSize, kPieceSize, 8, 0, imageColorSpace, kCGImageAlphaPremultipliedFirst); CGRect rectPiece= CGRectMake(fmodf(i, appDelegate().puzzleSize) * kPieceDistance, (floorf(i / appDelegate().puzzleSize)) * kPieceDistance, kPieceSize, kPieceSize); [self.arrlocations addObject:[NSValue valueWithCGRect:rectPiece]]; CGContextTranslateCTM(context, (kPieceSize - kPieceDistance) / 2 - fmodf(i, appDelegate().puzzleSize) * kPieceDistance, (kPieceSize - kPieceDistance) / 2 - (appDelegate().puzzleSize - 1 - floorf(i / appDelegate().puzzleSize)) * kPieceDistance); CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image); subImage = CGBitmapContextCreateImage(context); CGContextRelease(context); tile = CGImageCreateWithMask(subImage, mask); imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kPieceSize, kPieceSize)]; [imageView setImage:[UIImage imageWithCGImage:tile]]; [imageView setUserInteractionEnabled:NO]; [pieces[i] addSubview:imageView]; CGImageRelease(tile); CGImageRelease(subImage); DLog(@"%f", pieces[i].frame.size.width); pieces[i].transform=CGAffineTransformScale(CGAffineTransformIdentity, kTransformScale, kTransformScale); DLog(@"%f %f",kTransformScale, pieces[i].frame.size.width); //Release puzzle piece mask; CGImageRelease(mask); } //Clean up CGColorSpaceRelease(maskColorSpace); CGColorSpaceRelease(imageColorSpace); CGImageRelease(image); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload