首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSTextAttachment的图像被翻转

NSTextAttachment的图像被翻转
EN

Stack Overflow用户
提问于 2018-04-04 19:14:14
回答 3查看 500关注 0票数 0
代码语言:javascript
复制
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
NSImage *image = [NSImage imageNamed:@"emotion"];;
attachment.image = image;
NSAttributedString *attributedString = [NSAttributedString  attributedStringWithAttachment: attachment];
[[_feedbackContent textStorage] appendAttributedString:attributedString];

将图像添加到NSTextAttachment后,它是垂直翻转的。任何人都知道如何解决这个问题。

EN

回答 3

Stack Overflow用户

发布于 2019-01-10 15:56:42

NSTextAttachment似乎使用NSFileWrapper文件名来获取UTI,并且基于UTI有不同的行为。

我可以使用NSFileWrapper来解决这个问题:

代码语言:javascript
复制
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:data];
// Without a filename (which is used to get the UTI by NSTextAttachment)
// the image is displayed flipped.
[fileWrapper setPreferredFilename:@"Attachment.png"];
NSTextAttachment  *attachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];

您还可以尝试将fileType属性设置为kUTTypePNG或其他图像类型以使其正常工作。

雷达://47170950

票数 4
EN

Stack Overflow用户

发布于 2019-05-21 01:09:40

将映像分配给NSTextAttachmentCell,而不是NSTextAttachment。

代码语言:javascript
复制
id <NSTextAttachmentCell> cell = [[NSTextAttachmentCell alloc] initImageCell:image];

NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
[attachment setAttachmentCell:cell];
票数 2
EN

Stack Overflow用户

发布于 2019-01-30 08:22:22

当绘制到翻转的视图时(这就是图像被翻转的原因),我发现的唯一解决办法是创建一个翻转的图像,然后将其绘制为:

代码语言:javascript
复制
textAttachment.image = [NSImage imageWithSize:image.size flipped:YES drawingHandler:^BOOL(NSRect dstRect) {
    [image drawInRect:dstRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
    return YES;
}];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49649553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档