gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:49 24 4
gpt4 key购买 nike

在我的 Ipad 应用程序中,我使用 OpenGL 框架来裁剪图像。我对 OpenGL 不太熟悉。在我的应用程序中,我需要裁剪图像的一部分并将其显示在 ImageView 中。对于裁剪效果,我使用 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

最佳答案

黑色通常意味着您无法从 OpenGL 中提取数据,最终得到一张空白图像。

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

关于iphone - 无法通过在 ipad 中使用 OpenGL 获得裁剪图像的确切部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15786026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com