Ios 裁剪大尺寸图像并在imageview中设置';s框架

Ios 裁剪大尺寸图像并在imageview中设置';s框架,ios,uiimageview,uiimage,cgrect,Ios,Uiimageview,Uiimage,Cgrect,这个问题问了很多时间,但我的问题完全不同 我从Json(web服务)获取图像。就像“http:/address/upload/book_icon/4353988696.jpg” 我需要在imageview中显示尺寸为85*130的图像。但大多数图像的大小都要大得多 例如:如果图像的大小为1000*650,那么我如何将此图像设置为85*130,而不下载它 为了更快地显示图像,我正在使用“SDWebImageManagerDelegate”,但需要快速裁剪图像并在imageview中显示,而不需要下

这个问题问了很多时间,但我的问题完全不同

我从Json(web服务)获取图像。就像“http:/address/upload/book_icon/4353988696.jpg”

我需要在imageview中显示尺寸为85*130的图像。但大多数图像的大小都要大得多

例如:如果图像的大小为1000*650,那么我如何将此图像设置为85*130,而不下载它

为了更快地显示图像,我正在使用“SDWebImageManagerDelegate”,但需要快速裁剪图像并在imageview中显示,而不需要下载

到目前为止我做了

NSString *stringURL = [NSString stringWithFormat:@"%@",[imageURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 85,130)];
        [imgView setBackgroundColor:[UIColor whiteColor]];
        imgView.tag = i;
但是由于裁剪了图像,所以没有使用下线来获取图像

        [imgView setImageWithURL:[NSURL URLWithString:stringURL] placeholderImage:[UIImage imageNamed:@"no_image.png"]];  
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:stringURL]];
        UIImage *image123temp = [UIImage imageWithData:data];
UIImage *objimgtemp = [self imageCrop:image123temp];

        imgView.image = objimgtemp; 
用这个来获取图像

        [imgView setImageWithURL:[NSURL URLWithString:stringURL] placeholderImage:[UIImage imageNamed:@"no_image.png"]];  
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:stringURL]];
        UIImage *image123temp = [UIImage imageWithData:data];
UIImage *objimgtemp = [self imageCrop:image123temp];

        imgView.image = objimgtemp; 
并使用该方法对图像进行裁剪

-(UIImage*)imageCrop:(UIImage*)original
{
UIImage *ret = nil;

// This calculates the crop area.

float originalWidth  = original.size.width;
float originalHeight = original.size.height;

float edge = fminf(originalWidth, originalHeight);

float posX = (originalWidth   - edge) / 2.0f;
float posY = (originalHeight  - edge) / 2.0f;


CGRect cropSquare = CGRectMake(posX, posY,
                               edge, edge);


// This performs the image cropping.

CGImageRef imageRef = CGImageCreateWithImageInRect([original CGImage], cropSquare);

ret = [UIImage imageWithCGImage:imageRef
                          scale:original.scale
                    orientation:original.imageOrientation];

CGImageRelease(imageRef);

NSLog(@"ret.......... %f == %f",ret.size.width,ret.size.height);

return ret;
}
如何快速获得裁剪图像


任何链接、教程、建议、代码都将非常有用。

位于远程URL的图像始终按原样下载。任何在远程服务器上创建映像缩略图版本的操作,或在客户端请求时自动缩放/自动复制映像的操作 是服务器端进程而不是客户端进程

现在,您可以创建一个简单的服务器端webrequest(用PHP或其他语言),它返回 裁剪后的图像当然会更小。 然后在客户端执行类似的操作:

NSString *stringURL = [NSString stringWithFormat:@"http://www.example.com/getCroppedImage?width=%f&height=%f&imagename=%@", width, height, someImageName];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:stringURL]];

你是说从服务器上获取缩略图?这是通常的做法,但服务器必须支持缩略图。我看你没有别的办法独自一人做那件事。如果你能得到的只是一个完整的图像文件,那么你需要下载一个完整的文件,在内存中解压,然后你才能裁剪、呈现或处理它。。。