[Cocoa]_[初级]_[在一张图片上添加图片水印和文字水印]

  -(void) doLoadImageData
{
    float width = 400;
    float height = 400;
    NSImage *finalImage = [[NSImage alloc] initWithSize:NSMakeSize(width,height)];
    
    //  obtain images - your sources may vary
    
    NSImage *mainImage = [[NSImage alloc] initWithContentsOfFile:@".../sourceImage.jpg"];
    
    NSImage *overImage = [[NSImage alloc] initWithContentsOfFile: @".../overImage.jpg"];
      
    [finalImage lockFocus];
    CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort];
    // draw the base image
    [mainImage drawInRect:NSMakeRect(0,width,height)  fromrect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
    
    // draw the overlay image at some offset point
    [overImage drawInRect:NSMakeRect(0,100,50,50)fromrect:NSZeroRect operation:NSCompositeSourceOver fraction:0.5 respectFlipped:YES hints:nil];
    
    [self MyDrawText:myContext];
    
    [finalImage unlockFocus];
   
    NSData *finalData = [finalImage TIFFRepresentation];
    NSBitmapImageRep *imageRep =[NSBitmapImageRep imageRepWithData:finalData];
    NSData *data =[imageRep representationUsingType:NSJPEGFileType properties:nil];
    [data writetoFile:@"/Users/mac-d1/work/waterMark.jpg" atomically:YES];
}

-(void) MyDrawText:(CGContextRef) myContext   // 1
{
    CGContextSelectFont (myContext,"Helvetica-Bold",10,kCGEncodingMacRoman);
    // CGContextSetCharacterSpacing (myContext,0.5); // 4
    CGContextSetTextDrawingMode (myContext,kCGTextFill); // 5
    
    CGContextSetRGBFillColor (myContext,1,0.5); // 6
    //CGContextSetRGBstrokeColor (myContext,0.2); // 7
    CGContextshowtextAtPoint (myContext,20,"www.Amacsoft.com",16); // 10
    
}

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...