Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static Stream GetImageStream(IList<Point> points,
return stream;
}

static Bitmap GetImageInternal(IList<Point> points,
static Bitmap? GetImageInternal(IList<Point> points,
float lineWidth,
Color strokeColor,
Color backgroundColor)
Expand All @@ -59,7 +59,7 @@ static Bitmap GetImageInternal(IList<Point> points,
var drawingHeight = points.Max(p => p.Y) - minPointY;
const int minSize = 1;
if (drawingWidth < minSize || drawingHeight < minSize)
throw new Exception($"The image size should be at least {minSize} x {minSize}.");
return null;

var image = Bitmap.CreateBitmap((int)drawingWidth, (int)drawingHeight, Bitmap.Config.Argb8888!)!;
using var canvas = new Canvas(image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static Stream GetImageStream(IList<Point> points,
}
}

static Bitmap GetImageInternal(IList<Point> points,
static Bitmap? GetImageInternal(IList<Point> points,
float lineWidth,
Color strokeColor,
Color backgroundColor)
Expand All @@ -62,7 +62,7 @@ static Bitmap GetImageInternal(IList<Point> points,
const int minSize = 1;
if (drawingWidth < minSize || drawingHeight < minSize)
{
throw new Exception($"The image size should be at least {minSize} x {minSize}.");
return null;
}

var bm = new Bitmap((int)drawingWidth, (int)drawingHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Stream GetImageStream(IList<Point> points,
return resizedImage.AsJPEG().AsStream();
}

static UIImage GetImageInternal(IList<Point> points,
static UIImage? GetImageInternal(IList<Point> points,
float lineWidth,
Color strokeColor,
Color backgroundColor)
Expand All @@ -53,7 +53,7 @@ static UIImage GetImageInternal(IList<Point> points,
const int minSize = 1;
if (drawingWidth < minSize || drawingHeight < minSize)
{
throw new Exception($"The image size should be at least {minSize} x {minSize}.");
return null;
}

var imageSize = new CGSize(drawingWidth, drawingHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ public static Stream GetImageStream(IList<Point> points,
}

var image = GetImageInternal(points, lineWidth, strokeColor, backgroundColor);
if (image is null)
{
return Stream.Null;
}

return image.AsTiff().AsStream();
}

static NSImage GetImageInternal(IList<Point> points,
static NSImage? GetImageInternal(IList<Point> points,
float lineWidth,
Color strokeColor,
Color backgroundColor)
Expand All @@ -47,7 +52,7 @@ static NSImage GetImageInternal(IList<Point> points,
const int minSize = 1;
if (drawingWidth < minSize || drawingHeight < minSize)
{
throw new Exception($"The image size should be at least {minSize} x {minSize}.");
return null;
}

var imageSize = new CGSize(drawingWidth, drawingHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static Stream GetImageStream(IList<Point> points,
}
}

static SKImage GetImageInternal(IList<Point> points,
static SKImage? GetImageInternal(IList<Point> points,
float lineWidth,
Color strokeColor,
Color backgroundColor)
Expand All @@ -58,7 +58,7 @@ static SKImage GetImageInternal(IList<Point> points,
const int minSize = 1;
if (drawingWidth < minSize || drawingHeight < minSize)
{
throw new Exception($"The image size should be at least {minSize} x {minSize}.");
return null;
}

var bm = new SKBitmap((int)drawingWidth, (int)drawingHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static Stream GetImageStream(IList<Point> points,
}
}

static CanvasRenderTarget GetImageInternal(IList<Point> points,
static CanvasRenderTarget? GetImageInternal(IList<Point> points,
float lineWidth,
Color lineColor,
Color backgroundColor)
Expand All @@ -62,7 +62,7 @@ static CanvasRenderTarget GetImageInternal(IList<Point> points,
const int minSize = 1;
if (drawingWidth < minSize || drawingHeight < minSize)
{
throw new Exception($"The image size should be at least {minSize} x {minSize}.");
return null;
}

var device = CanvasDevice.GetSharedDevice();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static Stream GetImageStream(IList<Point> points,
}

var image = GetImageInternal(points, lineWidth, strokeColor, backgroundColor);
if (image is null)
{
return Stream.Null;
}

var resizedImage = MaxResizeImage(image, (float) imageSize.Width, (float) imageSize.Height);
using (resizedImage)
Expand All @@ -46,7 +50,7 @@ public static Stream GetImageStream(IList<Point> points,
}
}

static Bitmap GetImageInternal(ICollection<Point> points,
static Bitmap? GetImageInternal(ICollection<Point> points,
float lineWidth,
Color strokeColor,
Color backgroundColor)
Expand All @@ -58,7 +62,7 @@ static Bitmap GetImageInternal(ICollection<Point> points,
const int minSize = 1;
if (drawingWidth < minSize || drawingHeight < minSize)
{
throw new Exception($"The image size should be at least {minSize} x {minSize}.");
return null;
}

var bm = new Bitmap((int) drawingWidth, (int) drawingHeight);
Expand Down