English 中文(简体)
1. 建立特定规模的模拟
原标题:Create UIImage of a specific size

我怎么能从高潮中创造一百万分。 具体来说,我想创造小幅320x50。 然后,我能够从这个形象中汲取具体肤色的多面。

最佳回答

页: 1

根据我的经验,我可以指出:

<><>propotong>

- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
 UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize);
 [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
 UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 return scaledImage;
}

<>Resize

- (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize
{
 UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
 [image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
 UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 return reSizeImage;
}

www.un.org/Depts/DGACM/index_spanish.htm 具体见。

<><>>> 页: 1

-(UIImage*)captureView:(UIView *)theView
{
 CGRect rect = theView.frame; 
 UIGraphicsBeginImageContext(rect.size); 
 CGContextRef context = UIGraphicsGetCurrentContext(); 
 [theView.layer renderInContext:context]; 
 UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
 UIGraphicsEndImageContext(); 
 return img;
}

www.un.org/Depts/DGACM/index_spanish.htm 一系列图像:

CGRect captureRect = yourRect
CGRect viewRect = self.view.frame;
UIImage *viewImg;
UIImage *captureImg;

UIGraphicsBeginImageContext(viewRect.size); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
[self.view.layer renderInContext:context]; 
viewImg = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();

captureImg = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(viewImg.CGImage, captureRect)];

www.un.org/Depts/DGACM/index_spanish.htm Save thegram/strong>

Save in app

NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"image.png"];
[UIImagePNGRepresentation(image) writeToFile:path atomically:YES];

<><><>Save in Book

CGImageRef screen = UIGetScreenImage();
UIImage* image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
问题回答

I leave here my answer, just in case this can help in the future. This answer is valid on iOS10+

extension UIImage {
    static func image(with size: CGSize) -> UIImage {
        UIGraphicsImageRenderer(size: size)
            .image { $0.fill(CGRect(origin: .zero, size: size)) }
    }
}

so you can do: UIImage.image(with: CGSize(width: 320, height: 50))

https://stackoverflow.com/a/48441178/2000162“https://stackoverflow.com/a/48441178/2000162

You can:

  1. Create a CGBitmapContext using the color/pixel/dimensions/etc you will need.
  2. Use the context or manipulate pixels directly.
  3. Create a UIImage using the result of CGBitmapContextCreateImage




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签