【发布时间】:2011-01-25 22:54:10
【问题描述】:
我正在尝试调整从磁盘加载的图像的大小 - JPG 或 PNG(我不知道加载时的格式) - 然后将其保存回磁盘。
我有以下代码,我试图从 Objective-c 移植,但是我卡在了最后一部分。 Original Objective-C.
这可能不是实现我想做的最好的方式 - 任何解决方案都适合我。
int width = 100;
int height = 100;
using (UIImage image = UIImage.FromFile(filePath))
{
CGImage cgimage = image.CGImage;
CGImageAlphaInfo alphaInfo = cgimage.AlphaInfo;
if (alphaInfo == CGImageAlphaInfo.None)
alphaInfo = CGImageAlphaInfo.NoneSkipLast;
CGBitmapContext context = new CGBitmapContext(IntPtr.Zero,
width,
height,
cgimage.BitsPerComponent,
4 * width,
cgimage.ColorSpace,
alphaInfo);
context.DrawImage(new RectangleF(0, 0, width, height), cgimage);
/*
Not sure how to convert this part:
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage* result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap); // ok if NULL
CGImageRelease(ref);
*/
}
【问题讨论】:
标签: objective-c resize uiimage xamarin.ios