gpt4 book ai didi

ios - 裁剪并重新创建 UIImage

转载 作者:行者123 更新时间:2023-11-28 18:19:37 25 4
gpt4 key购买 nike

我想在对它进行像素操作之前裁剪 UIImage(不是 imageview)。在 ios 框架中是否有可靠的方法来执行此操作?

下面是我使用的android中的相关方法:

http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap(android.graphics.Bitmap, int, int, int, int) http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap(int, int, android.graphics.Bitmap.Config)

最佳答案

-(UIImage*)scaleToSize:(CGSize)size image:(UIImage*)image
{
UIGraphicsBeginImageContext(size);

// Draw the scaled image in the current context
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];

// Create a new image from current context
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();

// Pop the current context from the stack
UIGraphicsEndImageContext();

// Return our new scaled image
return scaledImage;
}

关于ios - 裁剪并重新创建 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23014447/

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