Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Scaling images that are @2x size (CurrentScale=2)

$
0
0

Greetings,

I have images that are 2X sized, I.E. in 1/2 pixel sizes. a 28x28 image that is 56x56 in number of pixels. In other words, I have a foo.png and a foo@2x.png file, and in this case, it is loading the @2x.

I want to rotate it correctly, here is code that works perfectly fine for "normal" images, but how do you set the CurrentScale Factor for an image? It appears to be in the constructor at the iOS level.

Here is my code:

    public static UIImage RotateImage (UIImage src, float angle)
    {
        UIImage Ret;
        float newSide = Math.Max (src.Size.Width, src.Size.Height);
        SizeF size = new SizeF (newSide, newSide);

        UIGraphics.BeginImageContext (size);
        CGContext context = UIGraphics.GetCurrentContext ();
        context.ScaleCTM (src.CurrentScale,src.CurrentScale);
        context.TranslateCTM (newSide / 2, newSide / 2);
        context.RotateCTM (angle);

        {

            context.RotateCTM (angle);
            src.Draw (new PointF (-src.Size.Width / 2, -src.Size.Height / 2));
            Ret = UIGraphics.GetImageFromCurrentImageContext ();        
        }

        UIGraphics.EndImageContext ();  // Restore context
 // Failed attempt:
 //         Ret.Scale (Ret.Size, src.CurrentScale);
        return Ret;
    }

Any ideas?

-Traderhut Games


Viewing all articles
Browse latest Browse all 204402

Trending Articles



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