- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 AdobeLabsUXMagicSelectionView我面临两个问题。我想使用以下两种方法“剪切”选定区域(前景):
方法一)getForeground:andMatte:
它没有给我正确的前景。当我选择一个区域并调用getForeground:andMatte
我给了我前景和背景(混合)。
选择狗的脸
剪狗的脸
文档说:
Alternatively, if you don’t need to process the underlying bitmap directly, and intend to use the results as inputs to CoreGraphics or CoreImage, you can call:
extension AdobeLabsUXMagicSelectionView {
func foregroundCGImage() -> CGImage {
let w = size_t(self.image.size.width)
let h = size_t(self.image.size.height)
let data = UnsafeMutablePointer<UInt8>(malloc(4 * w * h * sizeof(UInt8)))
self.readForegroundAndMatteIntoBuffer(data)
for var i = 0; i < 4 * w * h; i += 4 {
let alpha: UInt8 = UInt8(data[i + 3]) / 255
data[i] *= alpha
data[i + 1] *= alpha
data[i + 2] *= alpha
}
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.NoneSkipLast.rawValue)
let ctx = CGBitmapContextCreate(data, w, h, 8, 4 * w, CGColorSpaceCreateDeviceRGB(), bitmapInfo.rawValue)
let imageRef = CGBitmapContextCreateImage(ctx)!
return imageRef
}
}
@implementation AdobeLabsUXMagicSelectionView (Foreground)
- (UIImage *)getForeground {
// show the results
// first create a UIImage of just the foreground bits per the documentation in AdobeLabsUXMagicSelectionView.h
size_t w = self.image.size.width;
size_t h = self.image.size.height;
uint8_t *data = (uint8_t *)malloc(4*w*h*sizeof(uint8_t));
[self readForegroundAndMatteIntoBuffer:data];
// Paint the non-selected portion of the image black
for (int i = 0; i < 4*w*h; i += 4) {
float alpha = (float)data[i + 3] / 255;
data[i ] *= alpha;
data[i + 1] *= alpha;
data[i + 2] *= alpha;
}
CGContextRef ctx = CGBitmapContextCreate(data, w, h, 8, 4*w, CGColorSpaceCreateDeviceRGB(), (CGBitmapInfo)kCGImageAlphaNoneSkipLast);
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
UIImage * foregroundBits = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return foregroundBits;
}
@end
最佳答案
我认为问题在于您的比例因子类型为 uint8_t
所以你将比例因子剪裁为零。让它成为一个 float ,它应该工作。这是来自 MagicPuppy(在 objective-c 中)的代码:
// show the results
// first create a UIImage of just the foreground bits per the documentation in AdobeLabsUXMagicSelectionView.h
size_t w = _magicSelectionView.image.size.width;
size_t h = _magicSelectionView.image.size.height;
uint8_t *data = (uint8_t *)malloc(4*w*h*sizeof(uint8_t));
[_magicSelectionView readForegroundAndMatteIntoBuffer:data];
// Paint the non-selected portion of the image black
for (int i = 0; i < 4*w*h; i += 4)
{
float alpha = (float)data[i + 3] / 255;
data[i ] *= alpha;
data[i + 1] *= alpha;
data[i + 2] *= alpha;
}
CGContextRef ctx = CGBitmapContextCreate(data, w, h, 8, 4*w, CGColorSpaceCreateDeviceRGB(), (CGBitmapInfo)kCGImageAlphaNoneSkipLast);
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
UIImage * foregroundBits = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
// show the results
_resultsView = [[UIImageView alloc] initWithFrame: CGRectMake(0, VIEW_Y_OFFSET, self.view.bounds.size.width, self.view.bounds.size.height-VIEW_Y_OFFSET)];
_resultsView.contentMode = UIViewContentModeScaleAspectFit;
[_resultsView setImage: foregroundBits];
[self.view addSubview: _resultsView];
关于ios - 从 AdobeLabsUXMagicSelectionView (Adobe Creative SDK) 获取前景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35043434/
我的应用程序可以正确接收通知,但无法显示包含收到的信息的弹出通知(如果应用程序已打开)。 注意:如果应用程序在后台,通知会毫无问题地显示。 我的代码: 我以这种方式收到通知: @Override pu
我需要根据收到远程推送通知的时间来处理它们。当应用程序在后台或终止时,如果我收到推送通知,当我点击推送通知时,我会在 ` 中处理它 - (void)application:(UIApplication
我想根据控件的状态更改/动画自定义按钮控件模板的 Foreground 属性。 在 RC0 之前,我设置了 ContentPresenter 的前景,给它一个 x:Name,并在 VisualStat
我正在尝试设置 block ,以便其前景色每次都会改变鼠标光标移到它上面,这是我的代码: Remove Message
Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅关注editing this post一个问题。 6
有时,当我执行“docker-compose up -d”时,我忘记了“-d”部分。因此它开始向我显示启动日志,如果我按Ctrl + C,它将终止所有过程并向我显示关闭日志。 我对此有几个问题: 如果
我有一个启动器风格的应用程序。用户启动应用程序后,时钟开始滴答作响,经过一定时间后,用户将返回到我的应用程序的主要 Activity,并被告知时间到了。 为了实现这一点,我有一个 AsyncTask,
我有一个 FrameLayout,我想通过选择器为它应用前景可绘制对象,我正在尝试实现“drawSelectorOnTop”但是为了简单的布局 现在当用户按下“state_pressed”时选择器不适
我很难改变 Angular 2 Material 的前景颜色。例如在工具栏中,文本是黑色的。我尝试用以下样式更改它 @import '~@angular/material/theming'; $pri
我有一个奇怪的案例。我的 swift ios 应用程序已连接到 Cloudkit。如果应用程序未运行(后台状态),我每次都会收到我的通知徽章和警报!如果应用程序正在运行,则不会收到任何通知!我知道它没
这个问题在这里已经有了答案: How to change Status Bar text color in iOS (59 个答案) How to change the status bar bac
我想知道是否可以更改共享元素过渡的 z 顺序?看: 我有一个带有图像的布局,它填满了整个屏幕。图片前面是一个显示图片标题的文本框。如果我点击文本框,将开始过渡到详细信息 Activity 。因此,我实
每当文本框获得焦点时,文本的边框和前景都会根据当前主题更改: 主题灯->边框:黑色,文字:白色,背景:透明 theme dark ->border:white, text:white, backgro
我最近开始熟悉 Web 应用程序开发并努力解决一个基本的 css 布局问题。 所需的布局是一个中心区域重叠几个背景元素。看这里: 此图像显示了所需的布局: 我也在 codepen 上破解过它: Cod
这是交易。我可以创建一个 ListBox 并为其设置样式。我可以编辑模板的副本,以便状态在 Expression Blend 3 中可用。我可以更改状态,以便在选择时修改行项目的背景颜色。但是由于 C
我可以通过这样做来改变 QImage 的背景: QPainter painter(&image); painter.setCompositionMode(QPainter::CompositionMo
我有一个为 iOS8 实现的共享扩展。该服务使用 OAuth 进行身份验证。我用于扩展的登录信息与容器应用共享。 问题是: 当我在扩展中时,然后应用程序切换到容器应用程序并注销,然后应用程序切换回包含
我有一个 WPF Canvas 项目,我从工具箱中将对象拖放到 Canvas 上。根据某些数据,其中一些对象应该闪烁或闪烁。我得到一个未处理的异常:无法在不可变对象(immutable对象)实例上设置
我是一名优秀的程序员,十分优秀!