在我的xamarin.mac应用程序中,我使用 SQLite 来保存数据库,个人资料图片也保存在数据库中,但我在处理大图像时遇到问题(例如4 MB大小),我只需要在上传时保存照片缩略图:
imgProfilePicture.Image = new NSImage (path);
Byte [] bytes = System.IO.File.ReadAllBytes (path);
_profilePic = Convert.ToBase64String (bytes);
我在db中保存了base64字符串.. here是c#中的简单解决方案:
Image image = Image.FromFile(fileName);
Image thumb = image.GetThumbnailImage(120, 120, ()=>false, IntPtr.Zero);
thumb.Save(Path.ChangeExtension(fileName, "thumb"));
我需要这样的东西,需要调整图像大小而不需要裁剪
答案 0 :(得分:0)
NSImage baseImage = new NSImage ("original.jpg", false);
NSImage tinyImage = new NSImage (new CoreGraphics.CGSize (32, 32));
tinyImage.LockFocus ();
baseImage.DrawInRect (new CoreGraphics.CGRect (0, 0, 32, 32), new CoreGraphics.CGRect (0, 0, baseImage.Size.Width, baseImage.Size.Height), NSCompositingOperation.Copy, 1.0f);
tinyImage.UnlockFocus ();
NSBitmapImageRep rep = new NSBitmapImageRep (tinyImage.AsTiff ());
NSData data = rep.RepresentationUsingTypeProperties (NSBitmapImageFileType.Jpeg);
data.Save ("tiny.jpg", true);