Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从路径中获取图像缩略图_C#_Cocoa_Thumbnails_Nsimage_Xamarin.mac - Fatal编程技术网

C# 从路径中获取图像缩略图

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字符串

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

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