通过在ipad中使用OpenGL无法获得精确的部分裁剪图像

时间:2013-04-03 11:24:59

标签: iphone ios objective-c ipad opengl-es

在我的Ipad应用程序中,我正在使用OpenGL框架裁剪图像。我对OpenGL并不熟悉。在我的应用程序中,我需要裁剪图像的某些部分并将其显示在图像视图上。对于裁剪效果我使用OpenGL框架。裁剪效果很好但是当我将图像分配给imageview时,全黑图像显示而不是裁剪图像。我没有得到我出错的地方。如果任何一个人工作,请指导我,也请发布/建议与我的要求相关的链接。

我正在使用此代码:_sourceImage是捕获的图像。

-(void)showResult
{

   UIImage *imageCrop;
   float scaleCrop;
   if (_sourceImage.size.width >= IMAGEWIDTH)
   {
       scaleCrop = IMAGEWIDTH / _sourceImage.size.width;
       imageCrop = [ImageCropViewController scaleImage:_sourceImage with:CGSizeMake(_sourceImage.size.width*scaleCrop, _sourceImage.size.height*scaleCrop)];
   }
   else
   {
       scaleCrop = 1;
       imageCrop = _sourceImage;

   }

   float scale = _sourceImage.size.width / resizeImage.size.width * 2;
   IplImage *iplImage = [ImageCropViewController CreateIplImageFromUIImage:imageCrop] ;
   Quadrilateral rectan;

   rectan.point[0].x = _touchLayer.rectan.pointA.x*scale*scaleCrop;
   rectan.point[0].y = _touchLayer.rectan.pointA.y*scale*scaleCrop;

   rectan.point[1].x = _touchLayer.rectan.pointB.x*scale*scaleCrop;
   rectan.point[1].y = _touchLayer.rectan.pointB.y*scale*scaleCrop;

   rectan.point[2].x = _touchLayer.rectan.pointC.x*scale*scaleCrop;
   rectan.point[2].y = _touchLayer.rectan.pointC.y*scale*scaleCrop;

   rectan.point[3].x = _touchLayer.rectan.pointD.x*scale*scaleCrop;
   rectan.point[3].y = _touchLayer.rectan.pointD.y*scale*scaleCrop;

   IplImage* dest = cropDoc2(iplImage,rectan);

   IplImage *image = cvCreateImage(cvGetSize(dest), IPL_DEPTH_8U, dest->nChannels);
   cvCvtColor(dest, image, CV_BGR2RGB);
   cvReleaseImage(&dest);



   UIImage *tempImage = [ImageCropViewController UIImageFromIplImage:image withImageOrientation:_sourceImage.imageOrientation];
  [self crop:tempImage];
  cvReleaseImage(&image);

}
-(void)crop:(UIImage*)image
{    
   //Adjust the image size, to scale the image to 1013 of width
   float targetWidth = 1000.0f;
   float scale = targetWidth / image.size.width;
   float scaleheight = image.size.height * scale;
   UIImage *imageToSent = [ImageCropViewController scaleImage:image with:CGSizeMake(targetWidth, scaleheight)];
   // Image data with compression
   imageData = UIImageJPEGRepresentation(imageToSent,0.75);
   NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
   NSString *caldate = [now description];
   appDelegate.imagefilePath= [NSString stringWithFormat:@"%@/%@.jpg", DOCUMENTS_FOLDER,caldate];
   [imageData writeToFile:appDelegate.imagefilePath atomically:YES];

   appDelegate.cropimage=imageToSent;


}

enter image description here

1 个答案:

答案 0 :(得分:0)

黑色通常意味着您无法将数据从OpenGL中拉出来,并且您最终得到了一张空白图片。

如何从OpenGL中恢复图像? OpenGL不适用于普通图像 - 您必须发出自定义OpenGL调用才能将图像拉入其中。