Hello Benedikt,

UIKit and CoreGraphics coordinates system are not identical [1]. You
can easily convert between them by translating and scaling the current
transform [2].

Happy Holidays,
Sebastien

[1] http://stackoverflow.com/q/10408786/220643
[2] http://stackoverflow.com/a/5716548/220643

On Thu, Dec 27, 2012 at 3:00 AM, Benedikt Hübschen
<[email protected]> wrote:
> Hi,
>
> I have a problem drawing downloaded png's on a context in a OwnerDrawn
> Element from MonoTouch.Dialog…
> Every "§$%&/()= image will be drawn rotated and i don't know why.. Showing
> the image in a webview displays them correct….
>
>
> public class SampleOwnerDrawnElement : OwnerDrawnElement
>
> {
>
> public string imagefile;
>
> UIImage XY;
>
> int maxWidth  = (int)(UIScreen.MainScreen.Bounds.Width-10);
>
> int maxHeight = (int)(UIScreen.MainScreen.Bounds.Width);
>
> int imgWidth = 0;
>
> int imgHeight = 0;
>
>
> public override float Height (RectangleF bounds)
>
> {
>
> return imgHeight / UIScreen.MainScreen.Scale ;
>
> }
>
>
> public SampleOwnerDrawnElement (System.Json.JsonValue JS) :
> base(UITableViewCellStyle.Default, "sampleOwnerDrawnElement")
>
> {
>
> string text = (string)JS ["link"];
>
> string url = BASEURL + (string)JS ["img1"] + ".png";
>
> int width = JS ["img1data"] ["0"];
>
> int height = JS ["img1data"] ["1"];
>
>
>
> var cur_width = width;
>
> double ratio = (int)(maxWidth * UIScreen.MainScreen.Scale) /
> (cur_width*UIScreen.MainScreen.Scale);
>
> imgHeight = (int)(((int)(height*UIScreen.MainScreen.Scale)) * ratio);
>
> imgWidth = (int)(maxWidth * UIScreen.MainScreen.Scale);
>
>
> maxHeight = (int)(imgHeight / UIScreen.MainScreen.Scale);
>
> if (!(System.IO.File.Exists (System.Environment.GetFolderPath
> (System.Environment.SpecialFolder.MyDocuments)+  "/news/" +
> System.IO.Path.GetFileName (url)))) {
>
> System.Net.WebClient WLL = new System.Net.WebClient();
>
> WLL.DownloadFileCompleted += delegate(object sender,
> System.ComponentModel.AsyncCompletedEventArgs e) {
>
> XY = UIImage.FromFile (System.Environment.GetFolderPath
> (System.Environment.SpecialFolder.MyDocuments)+  "/news/" +
> System.IO.Path.GetFileName (url));
>
> } ;
>
> WLL.DownloadFileAsync(new Uri(url),System.Environment.GetFolderPath
> (System.Environment.SpecialFolder.MyDocuments)+  "/news/" +
> System.IO.Path.GetFileName (url));
>
> }  else {
>
> XY = UIImage.FromFile (System.Environment.GetFolderPath
> (System.Environment.SpecialFolder.MyDocuments)+  "/news/" +
> System.IO.Path.GetFileName (url));
>
> }
>
> this.Text = text;
>
> }
>
> public string Text
>
> {
>
> get;set;
>
> }
>
> public override void Draw (RectangleF bounds, CGContext context, UIView
> view)
>
> {
>
> UIColor color = UIColor.FromPatternImage (UIImage.FromBundle
> ("images/back.png"));
>
> color.SetFill ();
>
> context.FillRect (bounds);
>
> bounds = new RectangleF (5, 5, maxWidth,maxHeight);
>
> UIColor.White.SetFill ();
>
> context.FillRect (bounds);
>
> int aXBound = 0;
>
> if (!( XY==null) ) {
>
> UIImage x;
>
> if(XY.CGImage.Width<=maxWidth) {
>
> x=XY;
>
> aXBound = (int)((maxWidth/2) - (XY.CGImage.Width/2));
>
> }  else {
>
> ImageResizer mX = new ImageResizer(XY);
>
> mX.RatioResizeToWidth(maxWidth*UIScreen.MainScreen.Scale);
>
> x=mX.ModifiedImage;
>
> }
>
> context.DrawImage(new
> RectangleF(5+aXBound,5,x.CGImage.Width/UIScreen.MainScreen.Scale,x.CGImage.Height/UIScreen.MainScreen.Scale),x.CGImage);
>
> }
>
> UIColor.FromRGBA (0,0,0,215).SetFill ();
>
> context.FillRect (new RectangleF(6,maxHeight-39,maxWidth-2,38));
>
> UIColor.White.SetColor();
>
> view.DrawString(this.Text, new RectangleF(10,maxHeight-35,maxWidth,40),
> UIFont.BoldSystemFontOfSize(14.0f), UILineBreakMode.TailTruncation);
>
> }
>
> }
>
>
>
> XY is an UIImage that will be downloaded when the element is created (if
> it's not already downloaded and stored locally, the cell is just white with
> a small black box containing the product-name)
>
>
> Thanks in advance,
>
> Benedikt
>
>
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to