Draw on CGLayer

24 03 2008

I modified Create an on-memory CGImageRef to draw the small blue rectangle on a CGLayer, and combines the CGLayer to the background graphics context to generate the image. The result should remain same.

const int height = 250;
const int width = 400;

CGColorSpaceRef  imageColorSpace = CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB );

CGContextRef context = CGBitmapContextCreate (NULL, width, height,
                                    8, width * 4,
                                    imageColorSpace, kCGImageAlphaPremultipliedLast);

CGContextSetRGBFillColor (context, 1.0, 0.8, 0.8, 1);
CGContextFillRect (context, CGRectMake (0, 0, width, height ));

// Addition starts here.
CGLayerRef          layer;
CGContextRef        layerContext;

layer = CGLayerCreateWithContext(context,CGSizeMake(width, height),NULL);
layerContext = CGLayerGetContext(layer);

CGContextSetRGBFillColor(layerContext, 0, 0, 1, 1);
CGContextFillRect (layerContext, CGRectMake (80, 80, 40, 30));

CGContextDrawLayerInRect(context, CGRectMake(0, 0, width, height), layer);
// Addition finished.

CGImageRef image = CGBitmapContextCreateImage(context);

[imageView setImage:image imageProperties:nil];

CGColorSpaceRelease( imageColorSpace );
CGLayerRelease(layer);
CGContextRelease(layerContext);
CGContextRelease(context);
CGImageRelease( image );




Create an on-memory CGImageRef

21 03 2008

To create an on-memory CGImageRef object and display it through IKImageView, follow these steps.

  1. Create a Bitmap Graphics Context with the CGBitmapContextCreate() function.
  2. Draw some graphics on the Bitmap Graphics Context.
  3. Create an CGImageRef object from the Bitmap Graphics Context with the CGBitmapContextCreateImage() function.This CGImageRef object contains the same image as the Bitmap Graphics Context drawn in step 2.
  4. Pass the CGImageRef to IKImageView.
const int height = 250;
const int width = 400;

CGColorSpaceRef  imageColorSpace =
        CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB );

CGContextRef context = CGBitmapContextCreate (NULL, width, height,
         8, width * 4, imageColorSpace,
         kCGImageAlphaPremultipliedLast);

CGContextSetRGBFillColor (context, 1.0, 0.8, 0.8, 1);
CGContextFillRect (context, CGRectMake (0, 0, width, height ));

CGContextSetRGBFillColor(context, 0, 0, 1, 1);
CGContextFillRect (context, CGRectMake (80, 80, 40, 30));

CGImageRef image = CGBitmapContextCreateImage(context);

[imageView setImage:image imageProperties:nil];

CGColorSpaceRelease( imageColorSpace );
CGContextRelease(context);
CGImageRelease( image );




Disable WYSIWYG HTML editor on WordPress

5 03 2008

Here is an option you can disable WordPress’s “visual editor”. After show your Dashboard,

1. Click “Users”

wordpress1

2. Click “Your Profile”

wordpress2

3. Uncheck “Use the visual rich editor when writing” and click “Update Profile >>”

wordpress3

I prefer this because visual editor almost always strips line breaks.