GVKun编程网logo

objective-c – 使用Cocoa / OSX合并/堆叠两张图像(合并两个堆)

9

本篇文章给大家谈谈objective-c–使用Cocoa/OSX合并/堆叠两张图像,以及合并两个堆的知识点,同时本文还将给你拓展cocoa–使用C弹跳下载堆栈停靠图标(不使用ObjectiveC)、C

本篇文章给大家谈谈objective-c – 使用Cocoa / OSX合并/堆叠两张图像,以及合并两个堆的知识点,同时本文还将给你拓展cocoa – 使用C弹跳下载堆栈停靠图标(不使用ObjectiveC)、Cocoa,objective-c如何调整png图像的大小?、ios – 是否有编译为Objective-C或与Objective-C二进制兼容的语言 – > Objective-C的Coffeescript、iOS 使用cocoapods导入ReactiveCocoa和ReactiveObjC框架等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

objective-c – 使用Cocoa / OSX合并/堆叠两张图像(合并两个堆)

objective-c – 使用Cocoa / OSX合并/堆叠两张图像(合并两个堆)

我有一个CG ImageRef(可以称之为原始图像)和一个透明的png(水印).我正在尝试写一个方法来将水印放在原始的顶部,并返回一个CGImageRef.

在iOS中,我将使用UIKit将它们绘制到一个上下文中,但OSX似乎不可能(不支持UIKit).

堆叠两张图片最简单的方法是什么?谢谢

解决方法

对于一个快速的肮脏的解决方案,您可以使用NSImage绘图API:
NSImage *background = [NSImage imageNamed:@"background"];NSImage *overlay = [NSImage imageNamed:@"overlay"];NSImage *newImage = [[NSImage alloc] initWithSize:[background size]];[newImage lockFocus];CGRect newImageRect = CGRectZero;newImageRect.size = [newImage size];[background drawInRect:newImageRect];[overlay drawInRect:newImageRect];[newImage unlockFocus];CGImageRef newImageRef = [newImage CGImageForProposedRect:NULL context:nil hints:nil];

如果你不喜欢,那么您期望的大多数CGContext API都可以跨平台,用于绘制更多的控制.同样,您可以查看NSGraphicsContext.

cocoa – 使用C弹跳下载堆栈停靠图标(不使用ObjectiveC)

cocoa – 使用C弹跳下载堆栈停靠图标(不使用ObjectiveC)

Firefox目前不是 bounce the Downloads box in the dock when a download is finished,比如Safari,Chrome和Camino.

如果Firefox是用Objective C编写的,您可以非常轻松地添加执行此操作所需的one line of Objective C code.但事实并非如此.有没有办法从C调用这个Cocoa函数,以便它可以添加到Firefox中,以便所有Mac用户受益?

解决方法

您可以使用Carbon API的CFNotificationCenterPostNotification.
碳是纯C.

文档和代码示例here.

Cocoa,objective-c如何调整png图像的大小?

Cocoa,objective-c如何调整png图像的大小?

我是 cocoa的新手,我正在尝试做的是调整NS Image的大小,但看起来我做错了,因为我的图像没有调整大小.我看了看其他问题,这种方法看起来应该有效:

- (void)scaleIcons:(Nsstring *)outputPath{
NSImage *anImage;
NSSize imageSize;
Nsstring *finalPath;

anImage = [self image];

imageSize = [anImage size];
imageSize.width = 512;
imageSize.height = 512;
[anImage setSize:imageSize];

finalPath = [outputPath stringByAppendingString:@"/icon_512x512.png"];

NSData *imageData = [anImage TIFFRepresentation];
NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithData:imageData];
NSData *dataToWrite = [rep representationUsingType:NSPNGFileType properties:nil];
[dataToWrite writetoFile:finalPath atomically:NO];
}

一切正常,除了我的图像没有缩放的事实.有人可以帮忙吗?

解决方法

因此,您的代码段省略了缩放/转换图像所需的操作.在尝试保存之前,请通过此方法传递图像:

- (NSImage *)scaleImage:(NSImage *)image toSize:(NSSize)targetSize
{
  if ([image isValid])
  {
    NSSize imageSize = [image size];
    float width  = imageSize.width;
    float height = imageSize.height;
    float targetWidth  = targetSize.width;
    float targetHeight = targetSize.height;
    float scaleFactor  = 0.0;
    float scaledWidth  = targetWidth;
    float scaledHeight = targetHeight;

    NSPoint thumbnailPoint = NSZeroPoint;

    if (!NSEqualSizes(imageSize,targetSize))
    {
      float widthFactor  = targetWidth / width;
      float heightFactor = targetHeight / height;

      if (widthFactor < heightFactor)
      {
        scaleFactor = widthFactor;
      }
      else
      {
        scaleFactor = heightFactor;
      }

      scaledWidth  = width  * scaleFactor;
      scaledHeight = height * scaleFactor;

      if (widthFactor < heightFactor)
      {
        thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
      }

      else if (widthFactor > heightFactor)
      {
        thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
      }

    NSImage *newImage = [[NSImage alloc] initWithSize:targetSize];

    [newImage lockFocus];

     NSRect thumbnailRect;
     thumbnailRect.origin = thumbnailPoint;
     thumbnailRect.size.width = scaledWidth;
     thumbnailRect.size.height = scaledHeight;

     [image drawInRect:thumbnailRect
              fromrect:NSZeroRect
             operation:NSCompositeSourceOver
              fraction:1.0];

    [newImage unlockFocus];
  }

  return newImage;
}

如果将其集成到现有方法中:

- (void)scaleIcons:(Nsstring *)outputPath{

    NSSize outputSize = NSMakeSize(512.0f,512.0f);
    NSImage *anImage  = [self scaleImage:[self image] toSize:outputSize];

    Nsstring *finalPath = [outputPath stringByAppendingString:@"/icon_512x512.png"];
    NSData *imageData = [anImage TIFFRepresentation];
    NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithData:imageData];
    NSData *dataToWrite = [rep representationUsingType:NSPNGFileType properties:nil];
   [dataToWrite writetoFile:finalPath atomically:NO];
}

ios – 是否有编译为Objective-C或与Objective-C二进制兼容的语言 – > Objective-C的Coffeescript

ios – 是否有编译为Objective-C或与Objective-C二进制兼容的语言 – > Objective-C的Coffeescript

我最近发现了 eero programming lanugage
我发现它的概念非常有趣.它似乎主要是语法糖,看起来很可读.

虽然它不直接编译到Objective-C,但它声称生成与Objective-C相同的二进制代码

Eero compiles down to the same binary code as Objective-C

Eero offers excellent,nearly seamless interoperability with
Objective-C,C,and C++.

我发现这种方法非常有趣,我想知道是否有类似的编程语言和项目提供与Objective-C和iOS的大腿集成.
我正在为Objective-C寻找类似Coffeescript的东西.

解决方法

虽然使用eero的主要方法是将其编译为本机代码,但它也支持源到源的转换(从eero到标准的Objective-C/C++).有关详细信息,请参阅 https://github.com/eerolanguage/eero/wiki/Translator.

它确实需要记录在一个更明显的地方……

iOS 使用cocoapods导入ReactiveCocoa和ReactiveObjC框架

iOS 使用cocoapods导入ReactiveCocoa和ReactiveObjC框架

cocoapods使用

ReactiveObjC -- 对应的是RAC的OC版本,最新3.1.0版本。

ReactiveCocoa--对应的是RAC的swift版本,最新7.1.0版本。

1.纯OC项目

只需要引入ReactiveObjC,podfile文件如下

platform :ios , "8.0"
 
use_frameworks!
 
target "RACTest" do
 
pod ''ReactiveObjC'', ''~> 3.1.0''
 
end

 

2.OC和Swift的混合项目

需要同时引入ReactiveObjC和ReactiveCocoa,podfile文件如

 
platform :ios , "8.0"
 
use_frameworks!
 
target "RACTest" do
 
pod ''ReactiveObjC'', ''~> 3.1.0''
 
pod ''ReactiveCocoa'', ''~> 7.1.0''
 
pod ''ReactiveObjCBridge'', ''~> 3.0.0''
 
end

 

3.如果是纯Swift项目

只需要引入ReactiveCocoa,podfile文件如下

platform :ios , "8.0"
 
use_frameworks!
 
target "RACTest" do
 
pod ''ReactiveCocoa'', ''~> 7.1.0''
 
end

 

我们今天的关于objective-c – 使用Cocoa / OSX合并/堆叠两张图像合并两个堆的分享就到这里,谢谢您的阅读,如果想了解更多关于cocoa – 使用C弹跳下载堆栈停靠图标(不使用ObjectiveC)、Cocoa,objective-c如何调整png图像的大小?、ios – 是否有编译为Objective-C或与Objective-C二进制兼容的语言 – > Objective-C的Coffeescript、iOS 使用cocoapods导入ReactiveCocoa和ReactiveObjC框架的相关信息,可以在本站进行搜索。

本文标签: