ios - Get foreground from AdobeLabsUXMagicSelectionView (Adobe Creative SDK) -


i'm trying use adobelabsuxmagicselectionview , i'm facing 2 problems. wanna "cut" selected area (foreground) using these 2 methods:

method 1) getforeground:andmatte: doesn't give me correct foreground. when select area , call getforeground:andmatte gives me foreground , background (mixed).

selecting dog's face enter image description here

cutting dog's face enter image description here

documentation says:

alternatively, if don’t need process underlying bitmap directly, , intend use results inputs coregraphics or coreimage, can call:

method 2) after i'm trying "cut" documentation does

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)          var = 0; < 4 * w * h; += 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     }  } 

but paints (black) non-selected portion (background) of image.

anyone can help? want final image of selected area.

update:

as @donwoodward said i've create cattegory:

@implementation adobelabsuxmagicselectionview (foreground)  - (uiimage *)getforeground {     // show results     // first create uiimage of foreground bits per 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 non-selected portion of image black     (int = 0; < 4*w*h; += 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 

but result has lot of black pixel around "foreground".

enter image description here enter image description here

what need? "clean" foreground (selected area without black pixels) put on uiimageview

in case, you're premultiplying rgb channels alpha channel, implies want use kcgimagealphapremultipliedlast when creating context, in:

// paint non-selected portion of image black (int = 0; < 4*w*h; += 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)kcgimagealphapremultipliedlast); cgimageref imageref = cgbitmapcontextcreateimage(ctx); uiimage * foregroundbits = [uiimage imagewithcgimage:imageref]; cgimagerelease(imageref); 

more information can found in cgimage docs

also, try using cgimagecreatewithmask output of

- (void)getforeground:(uiimage **)foregroundimage andmatte:(uiimage **)matteimage 

as described in quartz 2d programming guide

uiimage *fg; uiimage *matte;  [_magicselectionview getforeground:&fg andmatte:&matte];  cgimageref mattedforeground = cgimagecreatewithmask(fg.cgimage, matte.cgimage); uiimage *foregroundbits = [uiimage imagewithcgimage:mattedforeground];  // show 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]; 

if neither of these works, it's possible there might issues configuration of uiimageviews being used render results, without code it's hard say.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -