Dr.Kameleon
Dr.Kameleon

Reputation: 22820

Adding an image border

OK, this is what I'm trying to do :

This is what I've achieved so far :

NSImage* resultImage = [[[self drop] image] copy];
[resultImage lockFocus];

NSRect newRect = NSMakeRect(0, 0, [[[self drop] image] size].width, [[[self drop] image] size].height);

[[[self drop2] image] drawInRect:newRect  
                        fromRect:NSZeroRect 
                       operation:NSCompositeSourceOver 
                        fraction:1.0];

[resultImage unlockFocus];

[[self drop] setImage:resultImage];

Where [self drop] is an ImageWell containing the photo, and [self drop2] an ImageWell containing the border.

The thing is that it IS working. However, the resulting image is - quite obviously - showing a somewhat "stretched" border.

Image with Border

How could I resolve that? Given that the original photo should be of ANY dimensions, how could I make it to use a border (of some fixed dimensions) and still avoid stretching?

Upvotes: 1

Views: 1299

Answers (2)

Mundi
Mundi

Reputation: 80271

I would do this differently. Just size the image as desired and then add the border. You could do this just by having a simple view with black background, or a suitable image (assuming you want to have customizable image borders, like frames), sized to always keep the resulting border constant. Then you can generate a new image from that view, if you need to.

Upvotes: 1

Arkku
Arkku

Reputation: 42159

How about doing the border directly with CALayer, e.g.:

#import <QuartzCore/QuartzCore.h>

CALayer *layer = imageView.layer;
layer.borderColor = [[NSColor blackColor] CGColor];
layer.borderWidth = 10;

Upvotes: 1

Related Questions