繁体   English   中英

从路径中获取图像缩略图

[英]Get image thumbnail from the path

在我的xamarin.mac应用程序中,我使用SQLite保存数据库,配置文件图片也保存在数据库中,但是我在处理大图像时遇到问题(例如大小为4 MB),我只需要保存照片的缩略图,同时上传:

imgProfilePicture.Image = new NSImage (path);
Byte [] bytes = System.IO.File.ReadAllBytes (path);
_profilePic = Convert.ToBase64String (bytes);

我在db ..中保存了base64字符串, 这里是c#中的简单解决方案:

Image image = Image.FromFile(fileName);
    Image thumb = image.GetThumbnailImage(120, 120, ()=>false, IntPtr.Zero);
    thumb.Save(Path.ChangeExtension(fileName, "thumb"));

我需要这样的东西,需要调整图像大小而不需要裁剪它

        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);

哪个是https://stackoverflow.com/a/7576710/36782转换为C#

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM