@@ -273,7 +273,7 @@ public final class ImageMarker: NSObject, RCTBridgeModule {
273
273
274
274
func markImage( with image: UIImage , waterImages: [ UIImage ] , options: MarkImageOptions ) -> UIImage ? {
275
275
276
- var bg = image;
276
+ let bg = image;
277
277
let w = bg. size. width
278
278
let h = bg. size. height
279
279
UIGraphicsBeginImageContextWithOptions ( bg. size, false , options. backgroundImage. scale)
@@ -323,39 +323,43 @@ public final class ImageMarker: NSObject, RCTBridgeModule {
323
323
case . topLeft:
324
324
rect = CGRect ( origin: CGPoint ( x: 20 , y: 20 ) , size: size)
325
325
case . topCenter:
326
- rect = CGRect ( origin: CGPoint ( x: ( w - size . width ) / 2 , y: 20 ) , size: size)
326
+ rect = CGRect ( origin: CGPoint ( x: ( w - ww ) / 2 , y: 20 ) , size: size)
327
327
case . topRight:
328
- rect = CGRect ( origin: CGPoint ( x: w - size . width - 20 , y: 20 ) , size: size)
328
+ rect = CGRect ( origin: CGPoint ( x: w - ww - 20 , y: 20 ) , size: size)
329
329
case . bottomLeft:
330
- rect = CGRect ( origin: CGPoint ( x: 20 , y: h - size . height - 20 ) , size: size)
330
+ rect = CGRect ( origin: CGPoint ( x: 20 , y: h - wh - 20 ) , size: size)
331
331
case . bottomCenter:
332
- rect = CGRect ( origin: CGPoint ( x: ( w - size . width ) / 2 , y: h - size . height - 20 ) , size: size)
332
+ rect = CGRect ( origin: CGPoint ( x: ( w - ww ) / 2 , y: h - wh - 20 ) , size: size)
333
333
case . bottomRight:
334
- rect = CGRect ( origin: CGPoint ( x: w - size . width - 20 , y: h - size . height - 20 ) , size: size)
334
+ rect = CGRect ( origin: CGPoint ( x: w - ww - 20 , y: h - wh - 20 ) , size: size)
335
335
case . center:
336
- rect = CGRect ( origin: CGPoint ( x: ( w - size . width ) / 2 , y: ( h - size . height ) / 2 ) , size: size)
336
+ rect = CGRect ( origin: CGPoint ( x: ( w - ww ) / 2 , y: ( h - wh ) / 2 ) , size: size)
337
337
default :
338
338
rect = CGRect ( origin: CGPoint ( x: 20 , y: 20 ) , size: size)
339
339
}
340
340
} else {
341
- rect = CGRect ( x: Utils . parseSpreadValue ( v: watermarkOptions. X, relativeTo: w) ?? 20 , y: Utils . parseSpreadValue ( v: watermarkOptions. Y, relativeTo: h) ?? 20 , width: CGFloat ( ww ) , height: CGFloat ( wh ) )
341
+ rect = CGRect ( x: Utils . parseSpreadValue ( v: watermarkOptions. X, relativeTo: w) ?? 20 , y: Utils . parseSpreadValue ( v: watermarkOptions. Y, relativeTo: h) ?? 20 , width: diagonal , height: diagonal )
342
342
}
343
343
344
344
UIGraphicsBeginImageContextWithOptions ( CGSize ( width: diagonal, height: diagonal) , false , 1 )
345
345
let markerContext = UIGraphicsGetCurrentContext ( )
346
+ markerContext? . setFillColor ( UIColor . red. cgColor)
347
+ markerContext? . fill ( rect)
346
348
markerContext? . saveGState ( )
347
-
349
+
348
350
if watermarkOptions. imageOption. alpha != 1.0 {
349
351
markerContext? . beginTransparencyLayer ( auxiliaryInfo: nil )
350
352
markerContext? . setAlpha ( watermarkOptions. imageOption. alpha)
351
353
markerContext? . setBlendMode ( . multiply)
352
354
let markerImage = markerImg. rotatedImageWithTransform ( watermarkOptions. imageOption. rotate)
353
- markerContext? . draw ( markerImage. cgImage!, in: CGRect ( origin: . zero, size: CGSize ( width: diagonal, height: diagonal) ) )
355
+ let originPoint = CGPoint ( x: 0 , y: rect. height - markerImage. size. height)
356
+ markerContext? . draw ( markerImage. cgImage!, in: CGRect ( origin: originPoint, size: CGSize ( width: markerImage. size. width, height: markerImage. size. height) ) )
354
357
markerContext? . endTransparencyLayer ( )
355
358
356
359
} else {
357
360
let markerImage = markerImg. rotatedImageWithTransform ( watermarkOptions. imageOption. rotate)
358
- markerContext? . draw ( markerImage. cgImage!, in: CGRect ( origin: . zero, size: CGSize ( width: diagonal, height: diagonal) ) )
361
+ let originPoint = CGPoint ( x: 0 , y: rect. height - markerImage. size. height)
362
+ markerContext? . draw ( markerImage. cgImage!, in: CGRect ( origin: originPoint, size: CGSize ( width: markerImage. size. width, height: markerImage. size. height) ) )
359
363
}
360
364
markerContext? . restoreGState ( )
361
365
0 commit comments