Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Xamarin.iOS Page drawing in Xamarin Forms. Help with iOS equivalent to Graphics.DrawImage (Windows)

$
0
0

Hi there,

I am at the final stages of completion for an application which is built mainly with Xamarin Forms (Login+Main Page), the Main page contains a part of it which is drawn natively using a custom renderer. This section takes a list of drawing elements and creates a graphical representation of the users selections. I am porting this functionality from a windows application (web) and am looking for the iOS equivalent to the following.

if (drawingElement.Data != string.Empty) {
Image imageElement = new Bitmap(HttpContext.Current.Server.MapPath("../" + drawingElement.Data));

Rectangle sourceRectangle = new Rectangle(drawingElement.X2, drawingElement.Y2, drawingElement.Width, drawingElement.Height);
Rectangle destinationRectangle = new Rectangle(offSetX + drawingElement.X, offsetY + drawingElement.Y, drawingElement.Width, drawingElement.Height);

g.DrawImage(imageElement, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel);
sourceRectangle = null;
destinationRectangle = null;
imageElement = null;
}

thus far I have:

 if (element.Data != null && element.Data != string.Empty)
  {                               
       var img = UIImage.FromBundle(element.Data);

       UIImageView imgView = new UIImageView();
       RectangleF destRect = new RectangleF((offSetX + element.X / 5), (offSetY + element.Y / 5), element.Width / 5, element.Height / 5);
       RectangleF srcRect = new RectangleF(element.X2/5, element.Y2/5, element.Width/5, element.Height/5);
                            
       imgView.Frame = destRect;
       //imgView.Bounds = srcRect;
       //imgView.ClipsToBounds = true;
       imgView.Image = img;
                            
       this.Add(imgView);
   }

destRect puts the Image in the correct place; however the image inside the imageview needs to be moved and cropped so certain elements of the image align with other parts of my drawing.

Any help on the above would be greatly appreciated.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>