動かしたコードはXamarinですが、SwiftやObjective-Cで実現できるかの回答でも構いません。
以下のサンプルを動かしてみたのですが、
https://github.com/xamarin/ios-samples/tree/master/GraphicsAndAnimation/CoreGraphics
これは画像の上にCGContext.ShowText()で文字を書いているのですが、
これは下の画像がつぶされている状態なのでしょうか?それとも別なオブジェクトとしてレイヤーが重なっている状態なのでしょうか?
やりたいことは画像上の文字やスタンプ画像などを貼り付けた後に移動や編集をしたいのですが、
そのようにレイヤーごとに編集することは可能でしょうか?
▼描画処理のソースコード
c#
1using System; 2using UIKit; 3using CoreGraphics; 4 5namespace CoreGraphicsSamples 6{ 7 public class DrawnImageView : UIView 8 { 9 public DrawnImageView () 10 { 11 BackgroundColor = UIColor.White; 12 } 13 14 public override void Draw (CGRect rect) 15 { 16 base.Draw (rect); 17 18 using (CGContext g = UIGraphics.GetCurrentContext ()) { 19 20 // scale and translate the CTM so the image appears upright 21 g.ScaleCTM (1, -1); 22 g.TranslateCTM (0, -Bounds.Height); 23 g.DrawImage (rect, UIImage.FromFile ("MyImage.png").CGImage); 24 25 // translate the CTM by the font size so it displays on screen 26 float fontSize = 35f; 27 g.TranslateCTM (0, fontSize); 28 29 // set general-purpose graphics state 30 g.SetLineWidth (1.0f); 31 g.SetStrokeColor (UIColor.Yellow.CGColor); 32 g.SetFillColor (UIColor.Red.CGColor); 33 g.SetShadow (new CGSize (5, 5), 0, UIColor.Blue.CGColor); 34 35 // set text specific graphics state 36 g.SetTextDrawingMode (CGTextDrawingMode.FillStroke); 37 g.SelectFont ("Helvetica", fontSize, CGTextEncoding.MacRoman); 38 39 // show the text 40 g.ShowText ("Hello Core Graphics"); 41 } 42 } 43 } 44} 45 46
◆環境
Visual Studio 2017
Xamarin 4.12
Xamarin.iOS 12.2
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。