如题
UIImageView *shareImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, IMG_WIDTH*Big_Time, IMG_HEIGHT*Big_Time)];
Big_Time是3 里面的图片的宽和高我也同比放大了3倍 但是就是有一些模糊 这是为什么
这是放大图片的函数
- (UIImage *)clipImageWithScaleWithsize:(CGSize)asize
{
UIImage *newimage;
UIImage *image = self;
if (nil == image) {
newimage = nil;
}
else{
CGSize oldsize = image.size;
CGRect rect;
if (asize.width/asize.height > oldsize.width/oldsize.height) {
rect.size.width = asize.width;
rect.size.height = asize.width*oldsize.height/oldsize.width;
rect.origin.x = 0;
rect.origin.y = (asize.height - rect.size.height)/2;
}
else{
rect.size.width = asize.height*oldsize.width/oldsize.height;
rect.size.height = asize.height;
rect.origin.x = (asize.width - rect.size.width)/2;
rect.origin.y = 0;
}
UIGraphicsBeginImageContext(asize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToRect(context, CGRectMake(0, 0, asize.width, asize.height));
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background
[image drawInRect:rect];
newimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return newimage;
}
这是将UIimageview转化成图片
+(UIImage *)imageWithView:(UIView *)view
{
UIGraphicsBeginImageContext(view.bounds.size);
CGContextRef currnetContext = UIGraphicsGetCurrentContext();
[view.layer renderInContext:currnetContext];
// 从当前context中创建一个改变大小后的图片
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
// 使当前的context出堆栈
UIGraphicsEndImageContext();
return image;
}
ringa_lee2017-04-18 09:06:49
It’s not a code problem, it’s a problem with the image itself. The image is composed of thousands of pixels, and the clarity of the image is determined by its own resolution. The higher the resolution, the clearer the display. (Image resolution is the number of pixels contained in a unit inch)
As for pictures in png format, if the resolution of the picture itself is 640*960, there is no problem if you want to display it smaller than or equal to the size of the picture itself, if you want to display it larger than the picture itself For images with high resolution, blurring is inevitable. The total number of pixels remains the same, but the size of the displayed image becomes larger, so there are fewer pixels in one unit, and the corresponding resolution also becomes smaller, and the image will naturally become blurry.
If you want to solve the current problem you are encountering, let the UI produce high-resolution images when producing images.
Hope this solves your problem!
阿神2017-04-18 09:06:49
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *copied = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Enlarge the picture to be naturally blurred. You can also try iOS7, the new conversion method.
大家讲道理2017-04-18 09:06:49
When drawing, it is the size. The screen resolution should be twice the size. Try multiplying asize by 2
迷茫2017-04-18 09:06:49
This kind of bitmap will inevitably be blurred when enlarged.
Only vector images will not be blurry.
Don’t know what you want to do? The effect achieved by your code is to take a screenshot.
If you want to do something like picture editing, you need to get the original image and then draw it on a larger canvas. If you use a small picture, it will be blurry.
高洛峰2017-04-18 09:06:49
The people downstairs have already said the same thing. I would like to add one more thing: CG rendering will burn out the CPU very much.