开发者

iPhone GLImageProcessing

开发者 https://www.devze.com 2023-04-04 13:16 出处:网络
in one of the example of GLImageProcessing i m just changing the way of getting image but app get crashed help me please i have change the way in such a manner

in one of the example of GLImageProcessing i m just changing the way of getting image but app get crashed help me please i have change the way in such a manner

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
    // UIImage *image = image; // imageView is my image from camera
     UIImage* img11 = [UIImage imageNamed:@"image1.jpg"];

    NSData *imageData = UIImagePNGRepresentation(img11);
    [imageData writeToFile:savedImagePath atomically:NO];  


    NSArray *p开发者_如何学编程aths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentsDirectory1 = [paths1 objectAtIndex:0];
    NSString *getImagePath1 = [documentsDirectory1 stringByAppendingPathComponent:@"savedImage.png"];
    UIImage *imgGet = [UIImage imageWithContentsOfFile:getImagePath1];

    CGImageRef CGImage = imgGet.CGImage;

However earlier way was ....

CGImageRef CGImage = [UIImage imageNamed:[NSString stringWithUTF8String:name]].CGImage;


I am not much sure but UIImagePNGRepresentation gives internal data so read it back as data and then convert it into image using following lines.

NSData *data1  = [NSData dataWithContentsOfFile:@"filePath"];
UIImage *uiImage = [[UIImage alloc] initWithData:data1];"

Please consider following block also. Put check for nil to avoid unexpected execution.

Return Value An autoreleased data object containing the PNG data, or nil if there was a problem generating the data. This function may return nil if the image has no data or if the underlying CGImageRef contains data in an unsupported bitmap format.

Check if above is helpful...

0

精彩评论

暂无评论...
验证码 换一张
取 消