图片编辑iOS

时间:2015-06-16 12:45:30

标签: ios objective-c

我正在使用AssetPicker图片库。我的查询是,我捕捉图像肖像模式并显示图像我的图像视图和水平翻转图像是淀粉,并没有正确显示..

         - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
           {
          __weak typeof(self) weakSelf = self;

           if (CFStringCompare((CFStringRef) [info   object ForKey:UIImagePickerControllerMediaType], kUTTypeImage, 0) == kCFCompareEqualTo)
             {
           if(self.segmentedControl.selectedSegmentIndex ==1 && self.segmentedControl.hidden == NO)
           {
             self.segmentedControl.selectedSegmentIndex = 0;
            [self changeAssetType:YES endBlock:^{
            _strong typeof(weakSelf) strongSelf = weakSelf;
             UIImage *image = info[UIImagePickerControllerOriginalImage];
            [[NSNotificationCenter defaultCenter] removeObserver:strongSelf  name:ALAssetsLibraryChangedNotification object:nil];
            [strongSelf.assetsLibrary   writeImageToSavedPhotosAlbum:image.CGImage metadata:info[UIImagePickerControllerMediaMetadata] completionBlock:^(NSURL *assetURL, NSError *error) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self saveAssetsAction:assetURL error:error           isPhoto:YES];
                 });
                 DLog(@"writeImageToSavedPhotosAlbum");
                }];

             }];

       }
            else
            {
           UIImage *image = info[UIImagePickerControllerOriginalImage];

         [[NSNotificationCenter defaultCenter] removeObserver:self name:ALAssetsLibraryChangedNotification object:nil];
        [self.assetsLibrary writeImageToSavedPhotosAlbum:image.CGImage metadata:info[UIImagePickerControllerMediaMetadata] completionBlock:^(NSURL *assetURL, NSError *error) {
            __strong typeof(weakSelf) strongSelf = weakSelf;
            dispatch_async(dispatch_get_main_queue(), ^{
                [strongSelf saveAssetsAction:assetURL error:error isPhoto:YES];
            });
            DLog(@"writeImageToSavedPhotosAlbum");
        }];
          }
       }
         else 
           {
           if(self.segmentedControl.selectedSegmentIndex ==0 && self.segmentedControl.hidden == NO)
          {
            self.segmentedControl.selectedSegmentIndex = 1;
            [self changeAssetType:NO endBlock:^{
             __strong typeof(weakSelf) strongSelf = weakSelf;

             [[NSNotificationCenter defaultCenter] removeObserver:strongSelf name:ALAssetsLibraryChangedNotification object:nil];
             [strongSelf.assetsLibrary writeVideoAtPathToSavedPhotosAlbum:info[UIImagePickerControllerMediaURL] completionBlock:^(NSURL *assetURL, NSError *error) {
                DLog(@"assetURL %@",assetURL);
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self saveAssetsAction:assetURL error:error isPhoto:NO];
                  });
              }];

          }];
        }
              else
       {
          [[NSNotificationCenter defaultCenter] removeObserver:self name:ALAssetsLibraryChangedNotification object:nil];
          [self.assetsLibrary writeVideoAtPathToSavedPhotosAlbum:info[UIImagePickerControllerMediaURL] completionBlock:^(NSURL *assetURL, NSError *error) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self saveAssetsAction:assetURL error:error isPhoto:NO];
            });

        }];

    }
}

     [picker dismissViewControllerAnimated:YES completion:^{}];


}

水平翻转图像是我的代码

    UIImage *sourceImage = originalimg;

    CIImage *coreImage = [CIImage imageWithCGImage:sourceImage.CGImage];

     UIImage *imgMirror = [UIImage imageWithCIImage:coreImage scale:sourceImage.scale orientation:UIImageOrientationUpMirrored];

     CGRect rect = CGRectMake(0, 0, originalimg.size.width, originalimg.size.height);

      UIGraphicsBeginImageContext(rect.size);

    [imgMirror drawInRect:rect];

    originalimg = UIGraphicsGetImageFromCurrentImageContext();

    imgview2.image = originalimg;
UIGraphicsEndImageContext();

1 个答案:

答案 0 :(得分:0)

图像宽度与图像高度的交换值。

CGRect rect = CGRectMake(0, 0, originalimg.size.height, originalimg.size.width);

  

您的图片被拉伸,因为如果您正在挑选图像   尺寸400X800(纵向模式)然后你的新fliped图像也是   使用400X800维度而不是800X400创建。