Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:41:13+00:00 2026-06-03T19:41:13+00:00

I have an image I’m grabbing from AVFoundation: [stillImage captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error)

  • 0

I have an image I’m grabbing from AVFoundation:

[stillImage captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
    NSLog(@"image capture");

    NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
    UIImage *image = [[UIImage alloc] initWithData:imageData];

I’m then cropping this image by first converting to a CIImage:

beginImage = [CIImage imageWithCVPixelBuffer:CMSampleBufferGetImageBuffer(imageSampleBuffer) options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNull null], kCIImageColorSpace, nil]];

    //first we crop to a square
    crop = [CIFilter filterWithName:@"CICrop"];
    [crop setValue:[CIVector vectorWithX:0 Y:0 Z:70 W:70] forKey:@"inputRectangle"];
    [crop setValue:beginImage forKey:@"inputImage"];
    croppedColourImage = [crop valueForKey:@"outputImage"];

I’m then trying to convert this back to a CGImage so that I can save it out:

CGImageRef cropColourImage = [context createCGImage:croppedColourImage fromRect:[croppedColourImage extent]];
    UIImage *cropSaveImage = [UIImage imageWithCGImage:cropColourImage];


    //saving of the images
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

     [library writeImageToSavedPhotosAlbum:[cropSaveImage CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
     if (error) {
         NSLog(@"ERROR in image save :%@", error);
     } else
     {
         NSLog(@"SUCCESS in image save");
     }

     }];

However, this throws the error:

ERROR in image save :Error Domain=ALAssetsLibraryErrorDomain
Code=-3304 “Failed to encode image for saved photos.”
UserInfo=0x19fbd0 {NSUnderlyingError=0x18efa0 “Failed to encode image
for saved photos.”, NSLocalizedDescription=Failed to encode image for
saved photos.}

I’ve read elsewhere that this can happen if the image was 0x0 pixels, and that the conversion from CIImage to CGImage can cause the problem. Any ideas?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:41:14+00:00Added an answer on June 3, 2026 at 7:41 pm

    I got it working!

    What I did is replace all my code with:

    NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
    UIImage *image = [[UIImage alloc] initWithData:imageData];
    NSLog(@"*image size is: %@", NSStringFromCGSize(image.size));
    
    //test creating a new ciimage
    CIImage *ciImage = [[CIImage alloc] initWithCGImage:[image CGImage]];
    NSLog(@"ciImage extent: %@", NSStringFromCGRect([ciImage extent]));
    

    This gives me a usable CIImage. I can then have filter fun with it, before saving it with:

    CIImage *croppedColourImage = [crop outputImage];
    
    //convert it to a cgimage for saving
    CGImageRef cropColourImage = [context createCGImage:croppedColourImage fromRect:[croppedColourImage extent]];
    
    //saving of the images
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    
    [library writeImageToSavedPhotosAlbum:cropColourImage metadata:[croppedColourImage properties] completionBlock:^(NSURL *assetURL, NSError *error){
        if (error) {
            NSLog(@"ERROR in image save: %@", error);
        } else
        {
            NSLog(@"SUCCESS in image save");
            CGImageRelease(cropColourImage);
        }
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have image files in a directory which have downloaded from several resources. If
I have image control.I want to load image from my specific path. i have
I need to have image file path from the user and store the image
I have something like that - image loaded from file to picturebox1: then after
I have image 6750x6450 px and trying to display it with imshow() function from
How to crop an image coming from server into popup? I have image coming
I have image and txt file of same size say 200 KB. Now i
I have image upload, where I check, how big part of image is already
I have image A and image B. They are located in the different places
So I have Image like this (source: de-viz.ru ) I want to get something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.