Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Having trouble with objective-c drawing app...

Hello everybody it's not iOS problem but a MacOS language is nearly the same so I thought someone could help me :)

Inside the program I can drag in picture (jpg, png, etc.) and make it black and white then fill in the colors with brush. It's like masking. (http://i526.photobucket.com/albums/cc343/iumentus/ScreenShot2014-09-02at131420_zps81299de7.png)

But when I save it it still comes in B&W or in full color if I invert the mask (http://i526.photobucket.com/albums/cc343/iumentus/ateiviukas_zpsb41fae15.jpg)

My thoughts is that there are problems with mask:

- (void)genas {
    CIFilter *myNewFilter = [CIFilter filterWithName:@"CIBlendWithMask"];
    CGAffineTransform generateactualsizemask = CGAffineTransformMakeScale(5, 5);
    if (!isEfected) {
        if (!isInvert) {
            [myNewFilter setValue:bottomLayerImage forKey:@"inputBackgroundImage"];
            [myNewFilter setValue:[brushAccumulator.image imageByApplyingTransform:generateactualsizemask] forKey:@"inputMaskImage"];
            [myNewFilter setValue:topLayerImage forKey:@"inputImage"];
        } else {
            [myNewFilter setValue:topLayerImage forKey:@"inputBackgroundImage"];
            [myNewFilter setValue:[[brushAccumulator image] imageByApplyingTransform:generateactualsizemask] forKey:@"inputMaskImage"];
            [myNewFilter setValue:bottomLayerImage forKey:@"outputImage"];
        }
    } else {
        if (!isInvert) {
            [myNewFilter setValue:[effects_controller effects_workflow_for_actual_size_bottom] forKey:@"inputBackgroundImage"];
            [myNewFilter setValue:[brushAccumulator.image imageByApplyingTransform:generateactualsizemask] forKey:@"inputMaskImage"];
            [myNewFilter setValue:[effects_controller effects_workflow_for_actual_size_top] forKey:@"inputImage"];
        } else {
            [myNewFilter setValue:[effects_controller effects_workflow_for_actual_size_top] forKey:@"inputBackgroundImage"];
            [myNewFilter setValue:[[brushAccumulator image] imageByApplyingTransform:generateactualsizemask] forKey:@"inputMaskImage"];
            [myNewFilter setValue:[effects_controller effects_workflow_for_actual_size_bottom] forKey:@"outputImage"];
        }
    }
    actualsizeimage = [[myNewFilter valueForKey:@"outputImage"] retain];
}

Or it could be something with saving it:

- (IBAction)saveImage:(id)sender {
    if ([self image]) {
        save_panel  = [[NSSavePanel savePanel] retain];
        [save_panel setAllowedFileTypes:[NSArray arrayWithObjects:@"jpg", @"png", @"tiff", @"bmp", nil]];
        [save_panel setCanSelectHiddenExtension:YES];
        [save_panel setCanCreateDirectories:YES];
        [save_panel setAccessoryView:custom_save_panel_view];
        filename = [[filename stringByReplacingOccurrencesOfString:@"%20" withString:@" "] retain];
        [save_panel setNameFieldStringValue:filename];
        [saving_process_indicator setHidden:YES];


        [self format_selection_changed:nil];
        [save_panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger rezultatas) {


            if(rezultatas == NSOKButton){
                [saving_process_indicator setHidden:NO];
                [saving_process_indicator startAnimation:self];

                [self genas];
                NSBitmapImageRep *saveRep = [[NSBitmapImageRep alloc] initWithCIImage:actualsizeimage];
                NSLog(@"saveRep.width = %ld", (long)[saveRep pixelsWide]);
                NSSize size = NSMakeSize([saveRep pixelsWide]*72.0/app_window->image_dpi, [saveRep pixelsHigh]*72.0/app_window->image_dpi);
                [saveRep setSize:size];
                NSLog(@"size.width = %f", size.width);

                for (int i=0; i==3; i++) {
                    [actualsizeimage release];
                }

                NSData *saveData;
                if ([[format_selection titleOfSelectedItem] isEqualToString:@"JPG"]) {
                    NSDictionary * dict = @{NSImageCompressionFactor: @(quality_slider.floatValue)};
                    saveData = [saveRep representationUsingType:NSJPEGFileType properties:dict];
                } else if ([[format_selection titleOfSelectedItem] isEqualToString:@"PNG"]) {
                    saveData = [saveRep representationUsingType:NSPNGFileType properties:nil];
                } else if ([[format_selection titleOfSelectedItem] isEqualToString:@"TIFF"]) {
                    saveData = [saveRep representationUsingType:NSTIFFFileType properties:nil];
                } else {
                    saveData = [saveRep representationUsingType:NSBMPFileType properties:nil];
                }

                [saveData writeToFile:@([[[save_panel URL] path]  UTF8String]) atomically:NO];
                [saveRep release];

                [saving_process_indicator setHidden:YES];
                [saving_process_indicator stopAnimation:self];

                if (fromDropCheck) {
                    [app_window performSelector:@selector(updateAfterSaving) withObject:nil afterDelay:0.2];
                    fromDropCheck = NO;
                }
                if (fromDockCheck) {
                    [app_delegate performSelector:@selector(updateAfterSaving) withObject:nil afterDelay:0.2];
                }
                if (fromQuitCheck) {
                    [app_window performSelector:@selector(updateAfterSavingQuit) withObject:nil afterDelay:0.2];
                    fromQuitCheck = NO;
                }
                if (fromQuitCheckDock) {
                    [app_delegate updateAfterSavingQuit];
                    fromQuitCheckDock = NO;
                }
                isSaved = YES;

            } else if (rezultatas == NSCancelButton) {
                if (fromDropCheck) {
                    [app_window performSelector:@selector(updateAfterSavingCancel) withObject:nil afterDelay:0.2];
                    fromDropCheck = NO;
                }

                if (fromQuitCheck) {
                    fromQuitCheck = NO;
                }

                if (fromQuitCheckDock) {
                    [app_delegate updateIfNotSavedFromSavingQuit];
                    fromQuitCheckDock = NO;
                }

            }
        }];
        [save_panel release];
    } else {
        NSBeep();
    }

}

THANK YOU!