-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamWriting.cs
28 lines (25 loc) · 922 Bytes
/
StreamWriting.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.IO;
using SkiaSharp;
namespace Dithery_cli
{
public static class StreamWriting
{
public static void DitherAndWritePngStream(Stream outputStream, SKBitmap bitmap, DitheringBase<byte> ditherer, bool writeToSameBitmap = true)
{
byte[] bytes = ReadWriteBitmaps.ReadBitmapToColorBytes(bitmap);
TempByteImageFormat temp = new TempByteImageFormat(bytes, bitmap.Width, bitmap.Height, 3);
temp = (TempByteImageFormat)ditherer.DoDithering(temp);
if (writeToSameBitmap)
{
ReadWriteBitmaps.WriteToBitmap(bitmap, temp.GetPixelChannels);
bitmap.Encode(outputStream, SKEncodedImageFormat.Png, quality: 100);
}
else
{
SKBitmap tempBitmap = new SKBitmap(bitmap.Width, bitmap.Height, bitmap.ColorType, bitmap.AlphaType);
ReadWriteBitmaps.WriteToBitmap(tempBitmap, temp.GetPixelChannels);
tempBitmap.Encode(outputStream, SKEncodedImageFormat.Png, quality: 100);
}
}
}
}