Tôi đang cố gắng định lại kích thước hình ảnh được tải từ đĩa - JPG hoặc PNG (Tôi không biết định dạng khi tải) - và sau đó lưu lại vào đĩa.Thay đổi kích thước và lưu hình ảnh vào đĩa trong Monotouch
Tôi có mã sau mà tôi đã cố gắng chuyển từ mục tiêu-c, tuy nhiên tôi đã bị kẹt ở phần cuối cùng. Original Objective-C.
Đây có thể không phải là cách tốt nhất để đạt được những gì tôi muốn làm - mọi giải pháp đều tốt cho tôi.
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);
*/
}