33 lines
1.2 KiB
C#
Executable File
33 lines
1.2 KiB
C#
Executable File
using System.IO;
|
|
//using System.Linq;
|
|
// using MarketData.Utils;
|
|
//using System.Drawing.Imaging;
|
|
//using System.Runtime.InteropServices;
|
|
//using System.Drawing;
|
|
using SkiaSharp;
|
|
|
|
namespace MarketData.CNNProcessing
|
|
{
|
|
public static class BitmapExtensions
|
|
{
|
|
// This call is used to generate the training, test, and validation bitmaps..
|
|
// I noticed a large difference in the accuracy or the model when the quality parameter is 100.
|
|
// I therefore intentionally not using EncoderParameters to specify quality but instead taking the default quality.
|
|
public static void SaveJPG100(this SKBitmap bitmap, string filename)
|
|
{
|
|
if(File.Exists(filename))File.Delete(filename);
|
|
using FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write);
|
|
using SKImage image = SKImage.FromBitmap(bitmap);
|
|
using SKData encodedImage = image.Encode(SKEncodedImageFormat.Jpeg,100);
|
|
encodedImage.SaveTo(stream);
|
|
}
|
|
|
|
public static void SaveJPG100(this SKBitmap bitmap, Stream stream)
|
|
{
|
|
using SKImage image = SKImage.FromBitmap(bitmap);
|
|
using SKData encodedImage = image.Encode(SKEncodedImageFormat.Jpeg,100);
|
|
encodedImage.SaveTo(stream);
|
|
}
|
|
}
|
|
}
|