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

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

概述-(void) doLoadImageData{ float width = 400; float height = 400; NSImage *finalImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; // obtain images - your sources
  -(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    }
总结

以上是内存溢出为你收集整理的[Cocoa]_[初级]_[在一张图片上添加图片水印和文字水印]全部内容,希望文章能够帮你解决[Cocoa]_[初级]_[在一张图片上添加图片水印和文字水印]所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1052329.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存