inside my xamarin.mac application , I use SQLite to save database, profile picture is saved in database too, but I have problems with working big images (for ex. size 4 MB), I just need to save thumbnail of photo , while uploading :
imgProfilePicture.Image = new NSImage (path);
Byte [] bytes = System.IO.File.ReadAllBytes (path);
_profilePic = Convert.ToBase64String (bytes);
I save base64 string in db.. also , here is simple solution in c #:
Image image = Image.FromFile(fileName);
Image thumb = image.GetThumbnailImage(120, 120, ()=>false, IntPtr.Zero);
thumb.Save(Path.ChangeExtension(fileName, "thumb"));
I need something like this, need to resize image without cropping it
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);
Which is https://stackoverflow.com/a/7576710/36782 converted to C#
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.