【问题标题】:Get image thumbnail from the path从路径获取图片缩略图
【发布时间】:2017-03-10 05:25:13
【问题描述】:

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

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

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

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

我需要这样的东西,需要在不裁剪的情况下调整图像大小

【问题讨论】:

    标签: c# cocoa thumbnails nsimage xamarin.mac


    【解决方案1】:
            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#

    【讨论】:

      猜你喜欢
      • 2013-08-12
      • 2013-01-01
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 2013-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多