This repository was archived by the owner on May 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +23
-14
lines changed Expand file tree Collapse file tree 7 files changed +23
-14
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ public static Stream GetImageStream(IList<Point> points,
48
48
return stream ;
49
49
}
50
50
51
- static Bitmap GetImageInternal ( IList < Point > points ,
51
+ static Bitmap ? GetImageInternal ( IList < Point > points ,
52
52
float lineWidth ,
53
53
Color strokeColor ,
54
54
Color backgroundColor )
@@ -59,7 +59,7 @@ static Bitmap GetImageInternal(IList<Point> points,
59
59
var drawingHeight = points . Max ( p => p . Y ) - minPointY ;
60
60
const int minSize = 1 ;
61
61
if ( drawingWidth < minSize || drawingHeight < minSize )
62
- throw new Exception ( $ "The image size should be at least { minSize } x { minSize } ." ) ;
62
+ return null ;
63
63
64
64
var image = Bitmap . CreateBitmap ( ( int ) drawingWidth , ( int ) drawingHeight , Bitmap . Config . Argb8888 ! ) ! ;
65
65
using var canvas = new Canvas ( image ) ;
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public static Stream GetImageStream(IList<Point> points,
50
50
}
51
51
}
52
52
53
- static Bitmap GetImageInternal ( IList < Point > points ,
53
+ static Bitmap ? GetImageInternal ( IList < Point > points ,
54
54
float lineWidth ,
55
55
Color strokeColor ,
56
56
Color backgroundColor )
@@ -62,7 +62,7 @@ static Bitmap GetImageInternal(IList<Point> points,
62
62
const int minSize = 1 ;
63
63
if ( drawingWidth < minSize || drawingHeight < minSize )
64
64
{
65
- throw new Exception ( $ "The image size should be at least { minSize } x { minSize } ." ) ;
65
+ return null ;
66
66
}
67
67
68
68
var bm = new Bitmap ( ( int ) drawingWidth , ( int ) drawingHeight ) ;
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public static Stream GetImageStream(IList<Point> points,
41
41
return resizedImage . AsJPEG ( ) . AsStream ( ) ;
42
42
}
43
43
44
- static UIImage GetImageInternal ( IList < Point > points ,
44
+ static UIImage ? GetImageInternal ( IList < Point > points ,
45
45
float lineWidth ,
46
46
Color strokeColor ,
47
47
Color backgroundColor )
@@ -53,7 +53,7 @@ static UIImage GetImageInternal(IList<Point> points,
53
53
const int minSize = 1 ;
54
54
if ( drawingWidth < minSize || drawingHeight < minSize )
55
55
{
56
- throw new Exception ( $ "The image size should be at least { minSize } x { minSize } ." ) ;
56
+ return null ;
57
57
}
58
58
59
59
var imageSize = new CGSize ( drawingWidth , drawingHeight ) ;
Original file line number Diff line number Diff line change @@ -32,10 +32,15 @@ public static Stream GetImageStream(IList<Point> points,
32
32
}
33
33
34
34
var image = GetImageInternal ( points , lineWidth , strokeColor , backgroundColor ) ;
35
+ if ( image is null )
36
+ {
37
+ return Stream . Null ;
38
+ }
39
+
35
40
return image . AsTiff ( ) . AsStream ( ) ;
36
41
}
37
42
38
- static NSImage GetImageInternal ( IList < Point > points ,
43
+ static NSImage ? GetImageInternal ( IList < Point > points ,
39
44
float lineWidth ,
40
45
Color strokeColor ,
41
46
Color backgroundColor )
@@ -47,7 +52,7 @@ static NSImage GetImageInternal(IList<Point> points,
47
52
const int minSize = 1 ;
48
53
if ( drawingWidth < minSize || drawingHeight < minSize )
49
54
{
50
- throw new Exception ( $ "The image size should be at least { minSize } x { minSize } ." ) ;
55
+ return null ;
51
56
}
52
57
53
58
var imageSize = new CGSize ( drawingWidth , drawingHeight ) ;
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ public static Stream GetImageStream(IList<Point> points,
46
46
}
47
47
}
48
48
49
- static SKImage GetImageInternal ( IList < Point > points ,
49
+ static SKImage ? GetImageInternal ( IList < Point > points ,
50
50
float lineWidth ,
51
51
Color strokeColor ,
52
52
Color backgroundColor )
@@ -58,7 +58,7 @@ static SKImage GetImageInternal(IList<Point> points,
58
58
const int minSize = 1 ;
59
59
if ( drawingWidth < minSize || drawingHeight < minSize )
60
60
{
61
- throw new Exception ( $ "The image size should be at least { minSize } x { minSize } ." ) ;
61
+ return null ;
62
62
}
63
63
64
64
var bm = new SKBitmap ( ( int ) drawingWidth , ( int ) drawingHeight ) ;
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public static Stream GetImageStream(IList<Point> points,
50
50
}
51
51
}
52
52
53
- static CanvasRenderTarget GetImageInternal ( IList < Point > points ,
53
+ static CanvasRenderTarget ? GetImageInternal ( IList < Point > points ,
54
54
float lineWidth ,
55
55
Color lineColor ,
56
56
Color backgroundColor )
@@ -62,7 +62,7 @@ static CanvasRenderTarget GetImageInternal(IList<Point> points,
62
62
const int minSize = 1 ;
63
63
if ( drawingWidth < minSize || drawingHeight < minSize )
64
64
{
65
- throw new Exception ( $ "The image size should be at least { minSize } x { minSize } ." ) ;
65
+ return null ;
66
66
}
67
67
68
68
var device = CanvasDevice . GetSharedDevice ( ) ;
Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ public static Stream GetImageStream(IList<Point> points,
35
35
}
36
36
37
37
var image = GetImageInternal ( points , lineWidth , strokeColor , backgroundColor ) ;
38
+ if ( image is null )
39
+ {
40
+ return Stream . Null ;
41
+ }
38
42
39
43
var resizedImage = MaxResizeImage ( image , ( float ) imageSize . Width , ( float ) imageSize . Height ) ;
40
44
using ( resizedImage )
@@ -46,7 +50,7 @@ public static Stream GetImageStream(IList<Point> points,
46
50
}
47
51
}
48
52
49
- static Bitmap GetImageInternal ( ICollection < Point > points ,
53
+ static Bitmap ? GetImageInternal ( ICollection < Point > points ,
50
54
float lineWidth ,
51
55
Color strokeColor ,
52
56
Color backgroundColor )
@@ -58,7 +62,7 @@ static Bitmap GetImageInternal(ICollection<Point> points,
58
62
const int minSize = 1 ;
59
63
if ( drawingWidth < minSize || drawingHeight < minSize )
60
64
{
61
- throw new Exception ( $ "The image size should be at least { minSize } x { minSize } ." ) ;
65
+ return null ;
62
66
}
63
67
64
68
var bm = new Bitmap ( ( int ) drawingWidth , ( int ) drawingHeight ) ;
You can’t perform that action at this time.
0 commit comments