Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-20-2010, 04:26 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 5
nyte3k is on a distinguished road
Default Masked text with image

Okay, so I found an example on how to create masked text...
Code:
- (void)drawRect:(CGRect)rect
{
	CGContextRef context = UIGraphicsGetCurrentContext();

	// Draw a dark gray background
	[[UIColor blackColor] setFill];
	CGContextFillRect(context, rect);

	// Draw the text upside-down
	CGContextSaveGState(context);
	CGContextTranslateCTM(context, 0, rect.size.height);
	CGContextScaleCTM(context, 1.0, -1.0);
	[[UIColor whiteColor] setFill];
	[text drawInRect:rect withFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:124]];
	CGContextRestoreGState(context);

	// Create an image mask from what we've drawn so far
	CGImageRef alphaMask = CGBitmapContextCreateImage(context);

	// Draw a white background (overwriting the previous work)
	[[UIColor whiteColor] setFill];
	CGContextFillRect(context, rect);

    // Draw the image, clipped by the mask
	CGContextSaveGState(context);
	CGContextClipToMask(context, rect, alphaMask);

	[[UIImage imageNamed:@"shuttle.jpg"] drawInRect:rect];
	CGContextRestoreGState(context);
	CGImageRelease(alphaMask);
}
..and i found another on how to combine text to an image and create an image:

Code:
-(UIImage *)addText:(UIImage *)img text:(NSString *)text1{
    int w = img.size.width;
    int h = img.size.height; 
    //lon = h - lon;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
    
    CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
    CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);
	
    char* txt	= (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];// "05/05/09";
    CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman);
    CGContextSetTextDrawingMode(context, kCGTextFill);
    CGContextSetRGBFillColor(context, 255, 255, 255, 1);
	
	
    //rotate text
    CGContextSetTextMatrix(context, CGAffineTransformMakeRotation( -M_PI/4 ));
	
    CGContextShowTextAtPoint(context, 4, 52, txt, strlen(txt));
	
	
    CGImageRef imageMasked = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSpace);
	
    return [UIImage imageWithCGImage:imageMasked];
}
What I'm trying to do is combined the masked text to an image and create an image from that. Basically Imagine a background picture of a blue sky. I want text filled with a mask/pattern of clouds, and then that text placed on the blue sky image.

How could I go about accomplishing this?
nyte3k is offline   Reply With Quote
Reply

Bookmarks

Tags
core graphics, image, quartz

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 396
9 members and 387 guests
chemistry, daudrizek, HemiMG, jeroenkeij, Kirkout, PavelMik, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:00 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0