@@ -490,30 +490,25 @@ public void DrawDrawable (SKDrawable drawable, SKPoint p)
490490
491491 // DrawBitmap
492492
493- public void DrawBitmap ( SKBitmap bitmap , SKPoint p , SKPaint paint = null )
494- {
493+ public void DrawBitmap ( SKBitmap bitmap , SKPoint p , SKPaint paint = null ) =>
495494 DrawBitmap ( bitmap , p . X , p . Y , paint ) ;
496- }
497495
498496 public void DrawBitmap ( SKBitmap bitmap , float x , float y , SKPaint paint = null )
499497 {
500- if ( bitmap == null )
501- throw new ArgumentNullException ( nameof ( bitmap ) ) ;
502- SkiaApi . sk_canvas_draw_bitmap ( Handle , bitmap . Handle , x , y , paint == null ? IntPtr . Zero : paint . Handle ) ;
498+ using var image = SKImage . FromBitmap ( bitmap ) ;
499+ DrawImage ( image , x , y , paint ) ;
503500 }
504501
505502 public void DrawBitmap ( SKBitmap bitmap , SKRect dest , SKPaint paint = null )
506503 {
507- if ( bitmap == null )
508- throw new ArgumentNullException ( nameof ( bitmap ) ) ;
509- SkiaApi . sk_canvas_draw_bitmap_rect ( Handle , bitmap . Handle , null , & dest , paint == null ? IntPtr . Zero : paint . Handle ) ;
504+ using var image = SKImage . FromBitmap ( bitmap ) ;
505+ DrawImage ( image , dest , paint ) ;
510506 }
511507
512508 public void DrawBitmap ( SKBitmap bitmap , SKRect source , SKRect dest , SKPaint paint = null )
513509 {
514- if ( bitmap == null )
515- throw new ArgumentNullException ( nameof ( bitmap ) ) ;
516- SkiaApi . sk_canvas_draw_bitmap_rect ( Handle , bitmap . Handle , & source , & dest , paint == null ? IntPtr . Zero : paint . Handle ) ;
510+ using var image = SKImage . FromBitmap ( bitmap ) ;
511+ DrawImage ( image , source , dest , paint ) ;
517512 }
518513
519514 // DrawSurface
@@ -839,13 +834,8 @@ public SKData DrawLinkDestinationAnnotation (SKRect rect, string value)
839834
840835 public void DrawBitmapNinePatch ( SKBitmap bitmap , SKRectI center , SKRect dst , SKPaint paint = null )
841836 {
842- if ( bitmap == null )
843- throw new ArgumentNullException ( nameof ( bitmap ) ) ;
844- // the "center" rect must fit inside the bitmap "rect"
845- if ( ! SKRect . Create ( bitmap . Info . Size ) . Contains ( center ) )
846- throw new ArgumentException ( "Center rectangle must be contained inside the bitmap bounds." , nameof ( center ) ) ;
847-
848- SkiaApi . sk_canvas_draw_bitmap_nine ( Handle , bitmap . Handle , & center , & dst , paint == null ? IntPtr . Zero : paint . Handle ) ;
837+ using var image = SKImage . FromBitmap ( bitmap ) ;
838+ DrawImageNinePatch ( image , center , dst , paint ) ;
849839 }
850840
851841 public void DrawImageNinePatch ( SKImage image , SKRectI center , SKRect dst , SKPaint paint = null )
@@ -863,11 +853,8 @@ public void DrawImageNinePatch (SKImage image, SKRectI center, SKRect dst, SKPai
863853
864854 public void DrawBitmapLattice ( SKBitmap bitmap , int [ ] xDivs , int [ ] yDivs , SKRect dst , SKPaint paint = null )
865855 {
866- var lattice = new SKLattice {
867- XDivs = xDivs ,
868- YDivs = yDivs
869- } ;
870- DrawBitmapLattice ( bitmap , lattice , dst , paint ) ;
856+ using var image = SKImage . FromBitmap ( bitmap ) ;
857+ DrawImageLattice ( image , xDivs , yDivs , dst , paint ) ;
871858 }
872859
873860 public void DrawImageLattice ( SKImage image , int [ ] xDivs , int [ ] yDivs , SKRect dst , SKPaint paint = null )
@@ -881,32 +868,8 @@ public void DrawImageLattice (SKImage image, int[] xDivs, int[] yDivs, SKRect ds
881868
882869 public void DrawBitmapLattice ( SKBitmap bitmap , SKLattice lattice , SKRect dst , SKPaint paint = null )
883870 {
884- if ( bitmap == null )
885- throw new ArgumentNullException ( nameof ( bitmap ) ) ;
886- if ( lattice . XDivs == null )
887- throw new ArgumentNullException ( nameof ( lattice . XDivs ) ) ;
888- if ( lattice . YDivs == null )
889- throw new ArgumentNullException ( nameof ( lattice . YDivs ) ) ;
890-
891- fixed ( int * x = lattice . XDivs )
892- fixed ( int * y = lattice . YDivs )
893- fixed ( SKLatticeRectType * r = lattice . RectTypes )
894- fixed ( SKColor * c = lattice . Colors ) {
895- var nativeLattice = new SKLatticeInternal {
896- fBounds = null ,
897- fRectTypes = r ,
898- fXCount = lattice . XDivs . Length ,
899- fXDivs = x ,
900- fYCount = lattice . YDivs . Length ,
901- fYDivs = y ,
902- fColors = ( uint * ) c ,
903- } ;
904- if ( lattice . Bounds != null ) {
905- var bounds = lattice . Bounds . Value ;
906- nativeLattice . fBounds = & bounds ;
907- }
908- SkiaApi . sk_canvas_draw_bitmap_lattice ( Handle , bitmap . Handle , & nativeLattice , & dst , paint == null ? IntPtr . Zero : paint . Handle ) ;
909- }
871+ using var image = SKImage . FromBitmap ( bitmap ) ;
872+ DrawImageLattice ( image , lattice , dst , paint ) ;
910873 }
911874
912875 public void DrawImageLattice ( SKImage image , SKLattice lattice , SKRect dst , SKPaint paint = null )
0 commit comments