J'essaie d'utiliser AdobeLabsUXMagicSelectionView et je suis confronté à 2 problèmes. Je veux "couper" la zone sélectionnée (premier plan) en utilisant ces deux méthodes:Mise en avant de AdobeLabsUXMagicSelectionView (Adobe Creative SDK)
Méthode 1) getForeground:andMatte:
Il ne me donne pas le premier plan correct. Lorsque je sélectionne une zone et appelle getForeground:andMatte
je me donne au premier plan et à l'arrière-plan (mixte).
Documentation dit:
Sinon, si vous n'avez pas besoin de traiter le bitmap sous-jacent directement, et l'intention de utiliser les résultats comme entrées pour CoreGraphics ou CoreImage, vous pouvez appeler:
Méthode 2) Après cela, je suis en train de "couper" que la documentation ne
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
}
}
mais il ne les peintures (noir) la partie non sélectionnée (arrière-plan) de l'image.
Quelqu'un peut-il aider? Ce que je veux, c'est obtenir une image finale de la zone sélectionnée.
MISE À JOUR:
Comme @DonWoodward dit que j'ai créé cette Cattegory:
@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
Mais le résultat a beaucoup de pixel noir autour du "premier plan".
Ce que je besoin? Obtenir un avant-plan "propre" (zone sélectionnée sans pixels noirs) pour mettre un UIImageView
Cela fonctionne comme un charme :) – Klevison