Jump to content
You must now use your email address to sign in [click for more info] ×

Copy or Export of Objects as "Core Graphics"


Recommended Posts

I wish to copy (or export) the objects including the style as plain Core Craphics Code. 

 

Like you can do it in iDraw / Autodesk Graphic.

 

 

Sample:

 

If you select the star, right click onto and choose "Copy As > Core Craphics Code".

ua6Eiub.png

 

You'll get the raw Code of Core Craphics of the object and his style attributes in the pasteboard. So you could directly paste it in Xcode's code editor view. 

#if TARGET_OS_IPHONE
	CGContextRef ctx = UIGraphicsGetCurrentContext();	// iOS
#else
	CGContextRef ctx = [[NSGraphicsContext currentContext] graphicsPort];	// OS X
#endif

// enable the following lines for flipped coordinate systems
// CGContextTranslateCTM(ctx, 0, self.bounds.size.height);
// CGContextScaleCTM(ctx, 1, -1);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGFloat scaleFactor = 1;
// CGContextScaleCTM(ctx, scaleFactor, scaleFactor);

/*  Shape   */
CGMutablePathRef pathRef = CGPathCreateMutable();
CGPathMoveToPoint(pathRef, NULL, 252.668, 378.613);
CGPathAddLineToPoint(pathRef, NULL, 276.422, 300.098);
CGPathAddLineToPoint(pathRef, NULL, 211.055, 250.54);
CGPathAddLineToPoint(pathRef, NULL, 293.067, 248.869);
CGPathAddLineToPoint(pathRef, NULL, 320, 171.387);
CGPathAddLineToPoint(pathRef, NULL, 346.933, 248.869);
CGPathAddLineToPoint(pathRef, NULL, 428.945, 250.54);
CGPathAddLineToPoint(pathRef, NULL, 363.578, 300.098);
CGPathAddLineToPoint(pathRef, NULL, 387.332, 378.613);
CGPathAddLineToPoint(pathRef, NULL, 320, 331.759);
CGPathCloseSubpath(pathRef);

/*  Drop Shadow  */
CGFloat shadowColorComps[] = { 0.082, 0.09, 0.086, 0.5 };
CGColorRef shadowColor = CGColorCreate(colorSpace, shadowColorComps);

CGMutablePathRef shadowPath = CGPathCreateMutable();
CGPathMoveToPoint(shadowPath, NULL, 83.5, 170.365);
CGPathAddLineToPoint(shadowPath, NULL, 83.972, 171.723);
CGPathAddLineToPoint(shadowPath, NULL, 110.791, 248.876);
CGPathAddLineToPoint(shadowPath, NULL, 192.455, 250.54);
CGPathAddLineToPoint(shadowPath, NULL, 193.893, 250.57);
CGPathAddLineToPoint(shadowPath, NULL, 192.747, 251.439);
CGPathAddLineToPoint(shadowPath, NULL, 127.657, 300.786);
CGPathAddLineToPoint(shadowPath, NULL, 151.31, 378.968);
CGPathAddLineToPoint(shadowPath, NULL, 151.727, 380.345);
CGPathAddLineToPoint(shadowPath, NULL, 150.546, 379.523);
CGPathAddLineToPoint(shadowPath, NULL, 83.5, 332.868);
CGPathAddLineToPoint(shadowPath, NULL, 16.454, 379.523);
CGPathAddLineToPoint(shadowPath, NULL, 15.273, 380.345);
CGPathAddLineToPoint(shadowPath, NULL, 15.69, 378.968);
CGPathAddLineToPoint(shadowPath, NULL, 39.343, 300.786);
CGPathAddLineToPoint(shadowPath, NULL, -25.747, 251.439);
CGPathAddLineToPoint(shadowPath, NULL, -26.893, 250.57);
CGPathAddLineToPoint(shadowPath, NULL, -25.455, 250.54);
CGPathAddLineToPoint(shadowPath, NULL, 56.209, 248.876);
CGPathAddLineToPoint(shadowPath, NULL, 83.028, 171.723);
CGPathAddLineToPoint(shadowPath, NULL, 83.5, 170.365);
CGPathCloseSubpath(shadowPath);

CGMutablePathRef clipPath = CGPathCreateMutable();
CGPathMoveToPoint(clipPath, NULL, 202.107, 159.365);
CGPathAddLineToPoint(clipPath, NULL, 438.893, 159.365);
CGPathAddLineToPoint(clipPath, NULL, 438.893, 391.345);
CGPathAddLineToPoint(clipPath, NULL, 202.107, 391.345);
CGPathCloseSubpath(clipPath);
CGPathMoveToPoint(clipPath, NULL, 320.5, 170.365);
CGPathAddLineToPoint(clipPath, NULL, 320.028, 171.723);
CGPathAddLineToPoint(clipPath, NULL, 293.209, 248.876);
CGPathAddLineToPoint(clipPath, NULL, 211.545, 250.54);
CGPathAddLineToPoint(clipPath, NULL, 210.107, 250.57);
CGPathAddLineToPoint(clipPath, NULL, 211.253, 251.439);
CGPathAddLineToPoint(clipPath, NULL, 276.343, 300.786);
CGPathAddLineToPoint(clipPath, NULL, 252.69, 378.968);
CGPathAddLineToPoint(clipPath, NULL, 252.273, 380.345);
CGPathAddLineToPoint(clipPath, NULL, 253.454, 379.523);
CGPathAddLineToPoint(clipPath, NULL, 320.5, 332.868);
CGPathAddLineToPoint(clipPath, NULL, 387.546, 379.523);
CGPathAddLineToPoint(clipPath, NULL, 388.727, 380.345);
CGPathAddLineToPoint(clipPath, NULL, 388.31, 378.968);
CGPathAddLineToPoint(clipPath, NULL, 364.657, 300.786);
CGPathAddLineToPoint(clipPath, NULL, 429.747, 251.439);
CGPathAddLineToPoint(clipPath, NULL, 430.893, 250.57);
CGPathAddLineToPoint(clipPath, NULL, 429.455, 250.54);
CGPathAddLineToPoint(clipPath, NULL, 347.791, 248.876);
CGPathAddLineToPoint(clipPath, NULL, 320.972, 171.723);
CGPathAddLineToPoint(clipPath, NULL, 320.5, 170.365);
CGPathCloseSubpath(clipPath);

CGContextSaveGState(ctx);
CGContextAddPath(ctx, clipPath);
CGContextClip(ctx);

CGContextTranslateCTM(ctx, 2, 5);
CGContextSetShadowWithColor(ctx, CGSizeMake((237 * scaleFactor), 0), (5 * scaleFactor), shadowColor);
CGContextSetRGBFillColor(ctx, 0, 0, 0, 1);
CGContextAddPath(ctx, shadowPath);
CGContextFillPath(ctx);

CGContextRestoreGState(ctx);
CGColorRelease(shadowColor);
CGPathRelease(shadowPath);
CGPathRelease(clipPath);

CGContextSetRGBFillColor(ctx, 0.816, 0.82, 0.816, 1);
CGContextAddPath(ctx, pathRef);
CGContextFillPath(ctx);

CGContextSetLineWidth(ctx, 1);
CGContextSetRGBStrokeColor(ctx, 0.325, 0.306, 0.314, 1);
CGContextAddPath(ctx, pathRef);
CGContextStrokePath(ctx);

CGPathRelease(pathRef);
CGColorSpaceRelease(colorSpace);

I don't use Photoshop and never used Illustrator. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.