Xamarin.Forms Essentials Camera Stream To Byte then Using SkiaSharp Image Size Down
Xamarin.Forms Essentials Camera Stream To BMP >> SkiaSharp Use FileFormat Jpg or Png then Reduce File Size Down
카메라 이미지(Raw) Stream(15~18Mb) ->SkiaSharp BMP 파일 변환 -> SkiaSharp Jpg Encoding image (254Kb~1Mb)
SkiaSharp 2.80.3 Bug: SKBitmap.Decode() == always null error
// SKData encodedData = Simage.Encode(SKEncodedImageFormat.Jpeg, 100);
async Task TakePhotoAsync()
{
try
{
if (!MediaPicker.IsCaptureSupported)
{
return;
}
var file = await MediaPicker.CapturePhotoAsync(new MediaPickerOptions
{
Title = DateTime.Now.ToString("yyyyMMddhhmmsss"),
}).ConfigureAwait(true);
await LoadPhotoAsync(file);
}
catch (Exception ex)
{
Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}");
}
}
async Task LoadPhotoAsync(FileResult photo)
{
try
{
if (photo == null)
{
return;
}
var newFile = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
byte[] imageByte = null;
using (var stream = await photo.OpenReadAsync())
{
using (var newStream = File.OpenWrite(newFile))//newFile))
{
await stream.CopyToAsync(newStream);
}
using (FileStream newStream2 = File.Open(newFile, FileMode.Open, FileAccess.ReadWrite))
{
try
{
using var imgStream = new SKManagedStream(newStream2);
using var skData = SKData.Create(newStream2);
using var codec = SKCodec.Create(skData);
SKImage _Skimage = SKImage.FromEncodedData(skData);
using (SKData p = _Skimage.Encode(SKEncodedImageFormat.Jpeg, 25))
{
imageByte = p.ToArray();
}
}
catch (Exception Ex)
{
Console.WriteLine($"CapturePhotoAsync Err:" + Ex.Message);
return;
}
}
}
// Photo File image view
image2.Source = FileImageSource.FromFile(newFile);
string Essential_file_name = DateTime.Now.ToString("yyyyMMddhhmmsss") + ".jpg";
if (imageByte is null)
{
}
else
{
// 사진 저장.
Xamarin.Essentials.Preferences.Set(Essential_file_name, Convert.ToBase64String(imageByte));
}
}
catch (Exception Ex)
{
Console.WriteLine("Load Image ERROR:" + Ex.Message);
}
}
_________________________
ASP.NET Example code for core to implement captcha with skiashrpdeveloppaper.com/asp-net-example-code-for-core-to-implement-captcha-with-skiashrp/
ASP.NET Example code for core to implement captcha with skiashrp - Develop Paper
preface This paper does not implement a completed captcha sample, but provides another idea of using the drawing API under the current. Net core 2.0, and shows it in the form of a simple demo. Skia Skia is an open source 2D graphics library, which provides
developpaper.com
](https://developpaper.com/asp-net-example-code-for-core-to-implement-captcha-with-skiashrp/)