C# 从路径中获取图像缩略图
在我的xamarin.mac应用程序中,我使用SQLite保存数据库,配置文件图片也保存在数据库中,但我在处理大图像(例如大小为4 MB)时遇到问题,我只需要保存照片的缩略图,同时上传:C# 从路径中获取图像缩略图,c#,cocoa,thumbnails,nsimage,xamarin.mac,C#,Cocoa,Thumbnails,Nsimage,Xamarin.mac,在我的xamarin.mac应用程序中,我使用SQLite保存数据库,配置文件图片也保存在数据库中,但我在处理大图像(例如大小为4 MB)时遇到问题,我只需要保存照片的缩略图,同时上传: imgProfilePicture.Image = new NSImage (path); Byte [] bytes = System.IO.File.ReadAllBytes (path); _profilePic = Convert.ToBase64String (bytes); 我将base64字符串
imgProfilePicture.Image = new NSImage (path);
Byte [] bytes = System.IO.File.ReadAllBytes (path);
_profilePic = Convert.ToBase64String (bytes);
我将base64字符串保存在db中。。同样,c#中的简单解是:
我需要这样的东西,需要调整图像大小而不裁剪它
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);
转换为C#
转换为C#
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);