示例#1
0
        public override void Draw()
        {
            m_SBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, null, null,
                           RasterizerState.CullCounterClockwise, null, Resolution.getTransformationMatrix());

            base.Draw(); //Needs to be drawn first for the ExitDialog to be drawn correctly.

            m_BackgroundImg.Draw(m_SBatch, null, 0.0f);
            m_HeadSkinBrowser.Draw(m_SBatch, 0.7f);
            m_BodySkinBrowser.Draw(m_SBatch, 0.7f);

            //TODO: Find out why the ExitDialog is drawn behind the other buttons on the screen.
            m_ExitDialog.Draw(m_SBatch, 0.9f);

            m_SBatch.End();

            foreach (UIElement Element in m_PResult.Elements.Values)
            {
                if (Element.NeedsClipping)
                {
                    RasterizerState RasterState = new RasterizerState();
                    RasterState.ScissorTestEnable = true;
                    RasterState.CullMode          = CullMode.CullCounterClockwiseFace;

                    m_SBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, null, null,
                                   RasterState, null, Resolution.getTransformationMatrix());

                    Element.Draw(m_SBatch, 0.5f);

                    m_SBatch.End();
                }
            }
        }
示例#2
0
        public override void Draw()
        {
            base.Draw();

            BackgroundImg.Draw(m_SBatch, null, 0.0f);

            TabBackgroundImg1.Draw(m_SBatch, null, 0.5f);
            TabBackgroundImg2.Draw(m_SBatch, null, 0.5f);
            TabBackgroundImg3.Draw(m_SBatch, null, 0.5f);

            DescriptionTabBackgroundImg1.Draw(m_SBatch, null, 0.7f);
            DescriptionTabImage1.Draw(m_SBatch, null, 0.7f);

            EnterTabBackgroundImage1.Draw(m_SBatch, null, 0.5f);
            EnterTabImage1.Draw(m_SBatch, null, 0.5f);

            DescriptionTabBackgroundImg2.Draw(m_SBatch, null, 0.7f);
            DescriptionTabImage2.Draw(m_SBatch, null, 0.7f);

            EnterTabBackgroundImage2.Draw(m_SBatch, null, 0.5f);
            EnterTabImage2.Draw(m_SBatch, null, 0.5f);

            DescriptionTabBackgroundImg3.Draw(m_SBatch, null, 0.7f);
            DescriptionTabImage3.Draw(m_SBatch, null, 0.7f);

            EnterTabBackgroundImage3.Draw(m_SBatch, null, 0.5f);
            EnterTabImage3.Draw(m_SBatch, null, 0.5f);

            //DefaultHouseImg.Draw(m_SBatch, null, 0.0f);

            CreditsBackgroundImg.Draw(m_SBatch, null, 0.0f);
            //CityThumbnailBusyImg.Draw(m_SBatch, null, 0.0f);

            m_ExitDialog.Draw(m_SBatch, 0.9f);
        }
示例#3
0
        // Child proof the image by rounding the edges of the image
        internal static UIImage RemoveSharpEdges(UIImage image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            float size = HighRes ? 73 : 48;

            UIGraphics.BeginImageContext(new SizeF(size, size));
            var c = UIGraphics.GetCurrentContext();

            if (HighRes)
            {
                c.AddPath(largePath);
            }
            else
            {
                c.AddPath(smallPath);
            }

            c.Clip();

            image.Draw(new RectangleF(0, 0, size, size));
            var converted = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(converted);
        }
示例#4
0
        private UIImage CropCircle(UIImage image)
        {
            // stretches the image if it's not square
            var newSize = image.Size;
            var minEdge = Math.Min(newSize.Height, newSize.Width);

            var size = new CGSize(width: minEdge, height: minEdge);

            UIGraphics.BeginImageContextWithOptions(size, false, 0.0f);
            var context = UIGraphics.GetCurrentContext();

            image.Draw(new CGRect(CGPoint.Empty, size), CGBlendMode.Copy, alpha: 1.0f);

            context.SetBlendMode(CGBlendMode.Copy);
            context.SetFillColor(UIColor.Clear.CGColor);

            var rect       = new CGRect(CGPoint.Empty, size: size);
            var rectPath   = UIBezierPath.FromRect(rect);
            var circlePath = UIBezierPath.FromOval(new CGRect(CGPoint.Empty, size: size));

            rectPath.AppendPath(circlePath);
            rectPath.UsesEvenOddFillRule = true;
            rectPath.Fill();

            var result = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(result);
        }
示例#5
0
        public static UIImage DrawResults(UIImage img, MultiboxGraph.Result result, float scoreThreshold)
        {
            Rectangle[] locations = ScaleLocation(result.DecodedLocations, (int)img.Size.Width, (int)img.Size.Height);

            UIGraphics.BeginImageContextWithOptions(img.Size, false, 0);
            var context = UIGraphics.GetCurrentContext();

            img.Draw(new CGPoint());
            context.SetStrokeColor(UIColor.Red.CGColor);
            context.SetLineWidth(2);
            for (int i = 0; i < result.Scores.Length; i++)
            {
                if (result.Scores[i] > scoreThreshold)
                {
                    Rectangle rect   = locations[result.Indices[i]];
                    CGRect    cgRect = new CGRect(rect.X, rect.Y, rect.Width, rect.Height);
                    context.AddRect(cgRect);
                    context.DrawPath(CGPathDrawingMode.Stroke);
                }
            }
            UIImage imgWithRect = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(imgWithRect);
        }
        private UIImage RotateImage(UIImage src, UIImageOrientation orientation)
        {
            UIGraphics.BeginImageContext(src.Size);

            if (orientation == UIImageOrientation.Right)
            {
                CGAffineTransform.MakeRotation((nfloat)radians(90));
            }
            else if (orientation == UIImageOrientation.Left)
            {
                CGAffineTransform.MakeRotation((nfloat)radians(-90));
            }
            else if (orientation == UIImageOrientation.Down)
            {
            }
            else if (orientation == UIImageOrientation.Up)
            {
                CGAffineTransform.MakeRotation((nfloat)radians(90));
            }

            src.Draw(new CGPoint(0, 0));
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(image);
        }
示例#7
0
        public static UIImage ResizeImage(UIImage source, float width, float height)
        {
            if (source == null)
            {
                return(source);
            }

            float imageWidth  = source.Size.Width;
            float imageHeight = source.Size.Height;

            float newImageHeight = height;
            float newImageWidth  = width;

            if (width == -1 && height != -1)
            {
                newImageWidth = imageWidth / (imageHeight / newImageHeight);
            }
            else if (width != -1 && height == -1)
            {
                newImageHeight = imageHeight / (imageWidth / newImageWidth);
            }

            try {
                UIGraphics.BeginImageContext(new System.Drawing.SizeF(newImageWidth, newImageHeight));
                source.Draw(new System.Drawing.RectangleF(0, 0, newImageWidth, newImageHeight));
                return(UIGraphics.GetImageFromCurrentImageContext());
            } finally
            {
                UIGraphics.EndImageContext();
            }
        }
示例#8
0
        private UIImage GetTrackWithTicksImage(CGRect innerRect, CGContext context, UIImage side)
        {
            var tickStartPointY = (innerRect.Height / 2) - (TickHeight / 2);
            var tickEndPointY   = (innerRect.Height / 2) + (TickHeight / 2);

            side.Draw(new CGPoint(0, 0));
            for (int i = 0; i < NumberOfTicks; i++)
            {
                context.SetLineWidth(TickWidth);

                var position = (innerRect.Size.Width / (NumberOfTicks - 1)) * i;

                if (i == 0)
                {
                    position += 1;
                }
                else if (i == NumberOfTicks - 1)
                {
                    position -= 1;
                }

                context.MoveTo(position, tickStartPointY);
                context.AddLineToPoint(position, tickEndPointY);

                context.SetStrokeColor(TickColor.CGColor);
                context.StrokePath();
            }

            return(UIGraphics.GetImageFromCurrentImageContext().CreateResizableImage(UIEdgeInsets.Zero));
        }
示例#9
0
        public override void Draw(SpriteBatch SBatch, float?LayerDepth)
        {
            float Depth;

            if (LayerDepth != null)
            {
                Depth = (float)LayerDepth;
            }
            else
            {
                Depth = 0.10f;
            }

            if (Visible)
            {
                Image.DrawTextureTo(SBatch, null, Image.Slicer.TLeft, Image.Position + Vector2.Zero, Depth);
                Image.DrawTextureTo(SBatch, Image.Slicer.TCenter_Scale, Image.Slicer.TCenter, Image.Position + new Vector2(Image.Slicer.LeftPadding, 0), Depth);
                Image.DrawTextureTo(SBatch, null, Image.Slicer.TRight, Image.Position + new Vector2(Image.Slicer.Width - Image.Slicer.RightPadding, 0), Depth);

                Image.DrawTextureTo(SBatch, Image.Slicer.CLeft_Scale, Image.Slicer.CLeft, Image.Position + new Vector2(0, Image.Slicer.TopPadding), null);
                Image.DrawTextureTo(SBatch, Image.Slicer.CCenter_Scale, Image.Slicer.CCenter, Image.Position + new Vector2(Image.Slicer.LeftPadding, Image.Slicer.TopPadding), Depth);
                Image.DrawTextureTo(SBatch, Image.Slicer.CRight_Scale, Image.Slicer.CRight, Image.Position + new Vector2(Image.Slicer.Width - Image.Slicer.RightPadding, Image.Slicer.TopPadding), Depth);

                int BottomY = Image.Slicer.Height - Image.Slicer.BottomPadding;
                Image.DrawTextureTo(SBatch, null, Image.Slicer.BLeft, Image.Position + new Vector2(0, BottomY), null);
                Image.DrawTextureTo(SBatch, Image.Slicer.BCenter_Scale, Image.Slicer.BCenter, Image.Position + new Vector2(Image.Slicer.LeftPadding, BottomY), Depth);
                Image.DrawTextureTo(SBatch, null, Image.Slicer.BRight, Image.Position + new Vector2(Image.Slicer.Width - Image.Slicer.RightPadding, BottomY), Depth);

                if (m_HasExitBtn)
                {
                    m_CloseBtnBack.Draw(SBatch, null, Depth);
                    m_CloseButton.Draw(SBatch, Depth);
                }
            }
        }
示例#10
0
        public override void Draw(RectangleF rect)
        {
            if (borderAt < 1)
            {
                return;
            }

            var context = UIGraphics.GetCurrentContext();

            context.SaveState();
            context.TranslateCTM(0, borderAt);
            context.AddPath(borderPath);
            UIColor.LightGray.SetColor();

            context.SetLineWidth(1);
            // Device and Sim interpret the Y for the shadow differently.
            context.SetShadowWithColor(new SizeF(0, -1), 3, UIColor.DarkGray.CGColor);
            context.StrokePath();

            // Clip the image to the path and paint it
            if (image != null)
            {
                context.AddPath(borderPath);
                context.Clip();
                image.Draw(new RectangleF(0, 0, 78, 78));
            }
            context.RestoreState();
        }
示例#11
0
        public static UIImage RoundCorners (UIImage image, int radius)
        {
			if (image == null)
				throw new ArgumentNullException ("image");
			
			UIImage converted = image;
			
			image.InvokeOnMainThread(() => {
	            UIGraphics.BeginImageContext (image.Size);
				float imgWidth = image.Size.Width;
				float imgHeight = image.Size.Height;
	
	            var c = UIGraphics.GetCurrentContext ();
	
	            c.BeginPath ();
	            c.MoveTo (imgWidth, imgHeight/2);
	            c.AddArcToPoint (imgWidth, imgHeight, imgWidth/2, imgHeight, radius);
	            c.AddArcToPoint (0, imgHeight, 0, imgHeight/2, radius);
	            c.AddArcToPoint (0, 0, imgWidth/2, 0, radius);
	            c.AddArcToPoint (imgWidth, 0, imgWidth, imgHeight/2, radius);
	            c.ClosePath ();
	            c.Clip ();
	
	            image.Draw (new PointF (0, 0));
	            converted = UIGraphics.GetImageFromCurrentImageContext ();
	            UIGraphics.EndImageContext ();
			});
			
            return converted;
        }
        // Child proof the image by rounding the edges of the image
        internal static UIImage RemoveSharpEdges (UIImage image)
        {
			if (image == null)
				throw new ArgumentNullException ("image");
			
            UIGraphics.BeginImageContext (image.Size);
			float imgWidth = image.Size.Width;
			float imgHeight = image.Size.Height;

            var c = UIGraphics.GetCurrentContext ();

            c.BeginPath ();
            c.MoveTo (imgWidth, imgHeight/2);
            c.AddArcToPoint (imgWidth, imgHeight, imgWidth/2, imgHeight, 4);
            c.AddArcToPoint (0, imgHeight, 0, imgHeight/2, 4);
            c.AddArcToPoint (0, 0, imgWidth/2, 0, 4);
            c.AddArcToPoint (imgWidth, 0, imgWidth, imgHeight/2, 4);
            c.ClosePath ();
            c.Clip ();

            image.Draw (new PointF (0, 0));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
示例#13
0
        public byte[] ResizeImage(byte[] imageData, float width, float height)
        {
            UIImage originalImage    = ImageUtils.FromByteArray(imageData);
            float   maxWidth         = 200;
            float   maxHeight        = 200;
            float   calculatedWidth  = width;
            float   calculatedHeight = height;

            var sourceSize      = originalImage.Size;
            var maxResizeFactor = Math.Max(maxWidth / sourceSize.Width, maxHeight / sourceSize.Height);

            if (maxResizeFactor > 1)
            {
                return(originalImage.AsJPEG().ToArray());
            }
            calculatedWidth  = (float)maxResizeFactor * (float)sourceSize.Width;
            calculatedHeight = (float)maxResizeFactor * (float)sourceSize.Height;

            UIGraphics.BeginImageContext(new SizeF(calculatedWidth, calculatedHeight));
            originalImage.Draw(new RectangleF(0, 0, calculatedWidth, calculatedHeight));
            var resultImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            string AvatarImageName    = "avatar.jpg";
            string PersonalFolderPath = "";
            string avatarFilename     = System.IO.Path.Combine(PersonalFolderPath, AvatarImageName);

            resultImage.AsJPEG().Save(avatarFilename, true);

            return(resultImage.AsJPEG().ToArray());
        }
示例#14
0
        public byte[] Resize(byte[] imageData, float maxWidth, float maxHeight)
        {
            UIImage sourceImage     = ImageFromByteArray(imageData);
            var     sourceSize      = sourceImage.Size;
            var     maxResizeFactor = (float)Math.Max(maxWidth / sourceSize.Width, maxHeight / sourceSize.Height);

            if (maxResizeFactor > 1)
            {
//				var rect = new CGRect (0, 0, sourceSize.Width, sourceSize.Height);
//				UIGraphics.BeginImageContext(sourceSize);
//				sourceImage.Draw (rect);
//				UIImage img = UIGraphics.GetImageFromCurrentImageContext();
//				var imageData = img.AsJPEG(0.5);
//				UIGraphicsEndImageContext();
                return(sourceImage.AsJPEG(0.5f).ToArray());
            }


            float width  = maxResizeFactor * (float)sourceSize.Width;
            float height = maxResizeFactor * (float)sourceSize.Height;

            UIGraphics.BeginImageContext(new SizeF(width, height));
            sourceImage.Draw(new RectangleF(0, 0, width, height));
            var resultImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(resultImage.AsJPEG(0.5f).ToArray());
        }
示例#15
0
        public static CVPixelBuffer ToCVPixelBuffer(this UIImage image, CGSize size)
        {
            var attrs = new CVPixelBufferAttributes
            {
                CGImageCompatibility         = true,
                CGBitmapContextCompatibility = true
            };
            var cgImg = image.Scale(size).CGImage;

            var pb = new CVPixelBuffer(cgImg.Width, cgImg.Height, CVPixelFormatType.CV32ARGB, attrs);

            pb.Lock(CVPixelBufferLock.None);
            var pData      = pb.BaseAddress;
            var colorSpace = CGColorSpace.CreateDeviceRGB();
            var ctxt       = new CGBitmapContext(pData, cgImg.Width, cgImg.Height, 8, pb.BytesPerRow, colorSpace, CGImageAlphaInfo.NoneSkipFirst);

            ctxt.TranslateCTM(0, cgImg.Height);
            ctxt.ScaleCTM(1.0f, -1.0f);
            UIGraphics.PushContext(ctxt);
            image.Draw(new CGRect(0, 0, cgImg.Width, cgImg.Height));
            UIGraphics.PopContext();
            pb.Unlock(CVPixelBufferLock.None);

            return(pb);
        }
示例#16
0
        public static UIImage ApplyTintEffect(UIImage image, UIColor color, TintColorModes mode)
        {
            UIGraphics.BeginImageContextWithOptions(image.Size, false, image.CurrentScale);

            try
            {
                UIImage result;
                using (CGContext g = UIGraphics.GetCurrentContext()) {
                    var rect = new CGRect(location: CGPoint.Empty, size: image.Size);

                    if (mode == TintColorModes.Solid)
                    {
                        image.Draw(rect);
                        g.SetFillColor(color.CGColor);
                        g.SetBlendMode(CGBlendMode.SourceAtop);
                        g.FillRect(rect);
                    }
                    else if (mode == TintColorModes.Gradient)
                    {
                        g.SetBlendMode(CGBlendMode.Normal);
                        g.SetFillColor(UIColor.Black.CGColor);
                        g.FillRect(rect);

                        // draw original image
                        // g.SetBlendMode(CGBlendMode.Normal);
                        // g.DrawImage(rect, image.CGImage);
                        image.Draw(rect, CGBlendMode.Normal, 1f);

                        // tint image (losing alpha) - the luminosity of the original image is preserved
                        g.SetBlendMode(CGBlendMode.Color);
                        g.SetFillColor(color.CGColor);
                        g.FillRect(rect);

                        // mask by alpha values of original image
                        // g.SetBlendMode(CGBlendMode.DestinationIn);
                        // g.DrawImage(rect, image.CGImage);
                        image.Draw(rect, CGBlendMode.DestinationIn, 1f);
                    }

                    result = UIGraphics.GetImageFromCurrentImageContext();
                }
                return(result);
            }
            finally {
                UIGraphics.EndImageContext();
            }
        }
示例#17
0
        public static UIImage BuildCoverFlow(UIImage image, float reflectionFraction)
        {
            int reflectionHeight = (int)(image.Size.Height * reflectionFraction);

            // gradient is always black and white and the mask must be in the gray colorspace
            var colorSpace = CGColorSpace.CreateDeviceGray();

            // Create the bitmap context
            var gradientBitmapContext = new CGBitmapContext(IntPtr.Zero, 1, reflectionHeight, 8, 0, colorSpace, CGImageAlphaInfo.None);

            // define the start and end grayscale values (with the alpha, even though
            // our bitmap context doesn't support alpha the gradien requires it)
            float [] colors = { 0, 1, 1, 1 };

            // Create the CGGradient and then release the gray color space
            var grayScaleGradient = new CGGradient(colorSpace, colors, null);

            colorSpace.Dispose();

            // create the start and end points for the gradient vector (straight down)
            var gradientStartPoint = new PointF(0, reflectionHeight);
            var gradientEndPoint   = PointF.Empty;

            // draw the gradient into the gray bitmap context
            gradientBitmapContext.DrawLinearGradient(grayScaleGradient, gradientStartPoint, gradientEndPoint, CGGradientDrawingOptions.DrawsAfterEndLocation);
            grayScaleGradient.Dispose();

            // Add a black fill with 50% opactiy
            gradientBitmapContext.SetFillColor(0, 0.5f);
            gradientBitmapContext.FillRect(new RectangleF(0, 0, 1, reflectionHeight));

            // conver the context into a CGImage and release the context
            var gradientImageMask = gradientBitmapContext.ToImage();

            gradientBitmapContext.Dispose();

            // create an image by masking the bitmap of the mainView content with the gradient view
            // then release the pre-masked content bitmap and the gradient bitmap
            var cgImage         = image.CGImage;
            var reflectionImage = cgImage.WithMask(gradientImageMask);

            cgImage.Dispose();
            gradientImageMask.Dispose();

            var size = new SizeF(image.Size.Width, image.Size.Height + reflectionHeight);

            UIGraphics.BeginImageContext(size);
            image.Draw(PointF.Empty);
            var context = UIGraphics.GetCurrentContext();

            context.DrawImage(new RectangleF(0, image.Size.Height, image.Size.Width, reflectionHeight), reflectionImage);

            var result = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            reflectionImage.Dispose();

            return(result);
        }
示例#18
0
        public Stream ResizeImage(
            Stream imageStream,
            double width,
            double height,
            string format = "jpeg",
            int quality   = 96)
        {
            if (imageStream == null)
            {
                return(null);
            }

            UIImage image = null;

            try {
                using (var memoryStream = new MemoryStream()) {
                    imageStream.CopyTo(memoryStream);
                    var data = memoryStream.ToArray();
                    image = UIImage.LoadFromData(NSData.FromArray(data));
                }
            } catch (Exception e) {
                Console.WriteLine($"ResizeImage: {e.Message}");
                return(null);
            }

            // No need to resize if required size is greater than original
            var scale = Math.Min(width / image.Size.Width,
                                 height / image.Size.Height);

            if (scale > 1.0)
            {
                return(imageStream);
            }

            width  = (float)(scale * image.Size.Width);
            height = (float)(scale * image.Size.Height);

            UIGraphics.BeginImageContextWithOptions(
                new CGSize(width, height),
                opaque: true,
                scale: 0);
            image.Draw(new CGRect(0, 0, width, height));
            var resized = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            var stream = new MemoryStream();

            var resizeData = ((format == "png") ?
                              resized.AsPNG().ToArray() :
                              resized.AsJPEG((nfloat)(0.01 * quality)).ToArray());

            image.Dispose();
            resized.Dispose();

            stream.Write(resizeData, 0, resizeData.Length);
            stream.Seek(0, SeekOrigin.Begin);
            return(stream);
        }
    public override bool DoDialog()
    {
        bool    result = false;
        GUISkin skin   = GUI.skin;

        GUI.skin = GUISkinFinder.Instance.GetGUISkin();
        imgList.Draw();
        labelList.Draw();
        mainLabel.Draw();
        isExitLabel.Draw();
        reciveCount.SetTextFormat(rewardCount, max);
        reciveCount.Draw();
        int num  = (int)(Time.realtimeSinceStartup - serverDataSinceTime);
        int num2 = (resetAfter - num) / 60;
        int num3 = num2 / 60;

        num2 %= 60;
        initializationTime.SetTextFormat(num3, num2);
        initializationTime.Draw();
        currentMyCoin.SetTextFormat(MyInfoManager.Instance.FreeCoin);
        currentMyCoin.Draw();
        pcbangPlusImage.Draw();
        timeGauge.valueNow = (float)(num + playTime);
        if (rewardCount == max)
        {
            timeGauge.valueNow = timeGauge.valueMax;
        }
        timeGauge.Draw();
        num2 = (cycle - playTime - num) / 60;
        num3 = num2 / 60;
        num2 = num2 % 60 + 1;
        if (num2 <= 0)
        {
            num2 = 1;
        }
        if (max == rewardCount)
        {
            num2 = 0;
        }
        remainTime.SetTextFormat(num2.ToString());
        remainTime.Draw();
        doneStamp.Draw();
        explain.SetTextFormat(max);
        explain.Draw();
        if (exit.Draw() || ok.Draw() || GlobalVars.Instance.IsEscapePressed())
        {
            result = true;
        }
        if (gameExit.Draw())
        {
            BuildOption.Instance.Exit();
        }
        if (!ContextMenuManager.Instance.IsPopup)
        {
            WindowUtil.EatEvent();
        }
        GUI.skin = skin;
        return(result);
    }
示例#20
0
 public static UIColor GetScaledImageBackground(this UIImage image, UIView view)
 {
     UIGraphics.BeginImageContext(view.Frame.Size);
     image.Draw(view.Frame);
     image = UIGraphics.GetImageFromCurrentImageContext();
     UIGraphics.EndImageContext();
     return(UIColor.FromPatternImage(image));
 }
示例#21
0
		public UIImage ResizeImage(UIImage sourceImage, float width, float height)
		{
			UIGraphics.BeginImageContext(new CGSize(width, height));
			sourceImage.Draw(new CGRect(0, 0, width, height));
			var resultImage = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();
			return resultImage;
		}
示例#22
0
文件: GraphicsII.cs 项目: 21Off/21Off
		public static UIImage Scale (UIImage image, SizeF size)
		{
			UIGraphics.BeginImageContext (size);
			image.Draw (new RectangleF (new PointF (0, 0), size));
			var ret = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();
			return ret;
		}		
		// resize the image (without trying to maintain aspect ratio)
		UIImage ResizeImage(UIImage sourceImage, float width, float height)
		{
			UIGraphics.BeginImageContext(new SizeF(width, height));
			sourceImage.Draw(new RectangleF(0, 0, width, height));
			var resultImage = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();
			return resultImage;
		}
        public override void Draw(RectangleF rect)
        {
            UIImage img   = null;
            UIColor color = UIColor.Gray;

            if (!Active || !Available)
            {
                //color = UIColor.FromRGBA(0.576f, 0.608f, 0.647f, 1f);
                //img = UIImage.FromBundle("Images/Calendar/datecell.png");
            }
            else if (Today && Selected)
            {
                //color = UIColor.White;
                img = UIImage.FromBundle("Images/Calendar/todayselected.png").CreateResizableImage(new UIEdgeInsets(4, 4, 4, 4));
            }
            else if (Today)
            {
                //color = UIColor.White;
                img = UIImage.FromBundle("Images/Calendar/today.png").CreateResizableImage(new UIEdgeInsets(4, 4, 4, 4));
            }
            else if (Selected || Marked)
            {
                //color = UIColor.White;
                img = UIImage.FromBundle("Images/Calendar/datecellselected.png").CreateResizableImage(new UIEdgeInsets(4, 4, 4, 4));
            }
            else
            {
                color = UIColor.FromRGBA(0.275f, 0.341f, 0.412f, 1f);
                //img = UIImage.FromBundle("Images/Calendar/datecell.png");
            }

            if (img != null)
            {
                img.Draw(new RectangleF(0, 0, _mv.BoxWidth, _mv.BoxHeight));
            }

            color.SetColor();
            var inflated = new RectangleF(0, 5, Bounds.Width, Bounds.Height);

            DrawString(Text, inflated,
                       UIFont.BoldSystemFontOfSize(16),
                       UILineBreakMode.WordWrap, UITextAlignment.Center);

            //            if (Marked)
            //            {
            //                var context = UIGraphics.GetCurrentContext();
            //                if (Selected || Today)
            //                    context.SetRGBFillColor(1, 1, 1, 1);
            //                else if (!Active || !Available)
            //					UIColor.LightGray.SetColor();
            //				else
            //                    context.SetRGBFillColor(75/255f, 92/255f, 111/255f, 1);
            //                context.SetLineWidth(0);
            //                context.AddEllipseInRect(new RectangleF(Frame.Size.Width/2 - 2, 45-10, 4, 4));
            //                context.FillPath();
            //
            //            }
        }
示例#25
0
        public static UIImage CroppedToSize(this UIImage image, CGSize imageSize, CGPoint offset, bool mirror)
        {
            UIGraphics.BeginImageContextWithOptions(imageSize, true, 0f);

            image.Draw(offset);

            UIImage result = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();


            if (mirror)
            {
                UIImageOrientation imageOrientation = UIImageOrientation.Up;
                switch (result.Orientation)
                {
                case UIImageOrientation.Down:
                    imageOrientation = UIImageOrientation.DownMirrored;
                    break;

                case UIImageOrientation.DownMirrored:
                    imageOrientation = UIImageOrientation.Down;
                    break;

                case UIImageOrientation.Left:
                    imageOrientation = UIImageOrientation.LeftMirrored;
                    break;

                case UIImageOrientation.LeftMirrored:
                    imageOrientation = UIImageOrientation.Left;

                    break;

                case UIImageOrientation.Right:
                    imageOrientation = UIImageOrientation.RightMirrored;

                    break;

                case UIImageOrientation.RightMirrored:
                    imageOrientation = UIImageOrientation.Right;

                    break;

                case UIImageOrientation.Up:
                    imageOrientation = UIImageOrientation.UpMirrored;
                    break;

                case UIImageOrientation.UpMirrored:
                    imageOrientation = UIImageOrientation.Up;
                    break;

                default:
                    break;
                }
                result = new UIImage(result.CGImage, result.CurrentScale, imageOrientation);
            }
            return(result);
        }
        public override void Draw(RectangleF rect)
        {
            WeatherForecastAnnotation annotation;
            CGPath path;

            base.Draw(rect);

            annotation = Annotation as WeatherForecastAnnotation;
            if (annotation == null)
            {
                return;
            }

            // Get the current graphics context
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetLineWidth(1.0f);

            // Draw the gray pointed shape:
            path = new CGPath();
            path.MoveToPoint(14.0f, 0.0f);
            path.AddLineToPoint(0.0f, 0.0f);
            path.AddLineToPoint(55.0f, 50.0f);
            context.AddPath(path);

            context.SetFillColor(UIColor.LightGray.CGColor);
            context.SetStrokeColor(UIColor.Gray.CGColor);
            context.DrawPath(CGPathDrawingMode.FillStroke);

            // Draw the cyan rounded box
            path = new CGPath();
            path.MoveToPoint(15.0f, 0.5f);
            path.AddArcToPoint(59.5f, 00.5f, 59.5f, 05.0f, 5.0f);
            path.AddArcToPoint(59.5f, 69.5f, 55.5f, 69.5f, 5.0f);
            path.AddArcToPoint(10.5f, 69.5f, 10.5f, 64.0f, 5.0f);
            path.AddArcToPoint(10.5f, 00.5f, 15.5f, 00.5f, 5.0f);
            context.AddPath(path);

            context.SetFillColor(UIColor.Cyan.CGColor);
            context.SetStrokeColor(UIColor.Blue.CGColor);
            context.DrawPath(CGPathDrawingMode.FillStroke);

            // Create the location & temperature string
            WeatherForecast forecast    = annotation.Forecast;
            NSString        temperature = new NSString(string.Format("{0}\n{1} / {2}", forecast.Place, forecast.High, forecast.Low));

            // Draw the text in black
            UIColor.Black.SetColor();
            temperature.DrawString(new RectangleF(15.0f, 5.0f, 50.0f, 40.0f), UIFont.SystemFontOfSize(11.0f));
            temperature.Dispose();

            // Draw the icon for the weather condition
            string  imageName = string.Format("WeatherMap.WeatherIcons.{0}.png", forecast.Condition);
            UIImage image     = UIImage.FromResource(typeof(WeatherAnnotationView).Assembly, imageName);

            image.Draw(new RectangleF(12.5f, 28.0f, 45.0f, 45.0f));
            image.Dispose();
        }
示例#27
0
        public static UIImage Resize(this UIImage self, CGSize newSize)
        {
            UIGraphics.BeginImageContextWithOptions(new CGSize(width: newSize.Width, height: newSize.Height), true, 1.0f);
            self.Draw(new CGRect(x: 0, y: 0, width: newSize.Width, height: newSize.Height));
            var resizedImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(resizedImage);
        }
示例#28
0
        public override void Draw()
        {
            m_SBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, null, null,
                           RasterizerState.CullCounterClockwise, null, Resolution.getTransformationMatrix());

            base.Draw();

            BackgroundImg.Draw(m_SBatch, null, 0.0f);

            TabBackgroundImg1.Draw(m_SBatch, null, 0.5f);
            TabBackgroundImg2.Draw(m_SBatch, null, 0.5f);
            TabBackgroundImg3.Draw(m_SBatch, null, 0.5f);

            DescriptionTabBackgroundImg1.Draw(m_SBatch, null, 0.7f);
            DescriptionTabImage1.Draw(m_SBatch, null, 0.7f);

            EnterTabBackgroundImage1.Draw(m_SBatch, null, 0.5f);
            EnterTabImage1.Draw(m_SBatch, null, 0.5f);

            DescriptionTabBackgroundImg2.Draw(m_SBatch, null, 0.7f);
            DescriptionTabImage2.Draw(m_SBatch, null, 0.7f);

            EnterTabBackgroundImage2.Draw(m_SBatch, null, 0.5f);
            EnterTabImage2.Draw(m_SBatch, null, 0.5f);

            DescriptionTabBackgroundImg3.Draw(m_SBatch, null, 0.7f);
            DescriptionTabImage3.Draw(m_SBatch, null, 0.7f);

            EnterTabBackgroundImage3.Draw(m_SBatch, null, 0.5f);
            EnterTabImage3.Draw(m_SBatch, null, 0.5f);

            //DefaultHouseImg.Draw(m_SBatch, null, 0.0f);

            CreditsBackgroundImg.Draw(m_SBatch, null, 0.0f);
            //CityThumbnailBusyImg.Draw(m_SBatch, null, 0.0f);

            m_ExitDialog.Draw(m_SBatch, 0.9f);

            m_SBatch.End();

            foreach (UIElement Element in m_PResult.Elements.Values)
            {
                if (Element.NeedsClipping)
                {
                    RasterizerState RasterState = new RasterizerState();
                    RasterState.ScissorTestEnable = true;
                    RasterState.CullMode          = CullMode.CullCounterClockwiseFace;

                    m_SBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, null, null,
                                   RasterState, null, Resolution.getTransformationMatrix());

                    Element.Draw(m_SBatch, 0.5f);

                    m_SBatch.End();
                }
            }
        }
示例#29
0
        //metodos:
        public UIImage ResizeImage(UIImage sourceImage, float width, float height)
        {         //ajustar el tamaño de las imagenes para que todas se vean genericas
            UIGraphics.BeginImageContext(new SizeF(width, height));
            sourceImage.Draw(new RectangleF(0, 0, width, height));
            var resultImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(resultImage);
        }
示例#30
0
		public static UIImage Stitch(UIImage left, UIImage right)
		{
			UIGraphics.BeginImageContext(new SizeF(left.Size.Width + right.Size.Width, left.Size.Height));
			left.Draw(new RectangleF(0, 0, left.Size.Width,left.Size.Height));
			right.Draw(new RectangleF(left.Size.Width, 0, right.Size.Width, right.Size.Height), CGBlendMode.Normal, 1.0f);
			UIImage stitched = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();			
			return stitched;
		}
示例#31
0
		public static UIImage CopyAndDispose(UIImage original)
		{
			UIGraphics.BeginImageContextWithOptions(original.Size, false, 0);
			original.Draw(new RectangleF(0, 0, original.Size.Width, original.Size.Height));
			UIImage copy = UIGraphics.GetImageFromCurrentImageContext();
		  	UIGraphics.EndImageContext();	
		    original.Dispose();
			return copy;
		}
示例#32
0
        public static UIImage ResizeImage(this UIImage sourceImage, float width, float height)
        {
            UIGraphics.BeginImageContext(new SizeF(width, height));
            sourceImage.Draw(new RectangleF(0, 0, width, height));
            var resultImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(resultImage);
        }
        public override void Draw(RectangleF rect)
        {
            base.Draw(rect);

            //Background zeichnen
            UIImage image = UIImage.FromBundle("NavigationBar.png");

            image.Draw(rect);
        }
        //Metoodo para ajustar la imagen en la tabla y se maneje un estandar
        public UIImage AjustarImagen(UIImage origenImagen, float ancho, float alto)
        {
            UIGraphics.BeginImageContext(new SizeF(ancho, alto));
            origenImagen.Draw(new RectangleF(0, 0, ancho, alto)); //imagen que llega al metodo.
            var destinoImagen = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();//qui se termina la edicion de la imagen
            return(destinoImagen);
        }
示例#35
0
 public override void Draw(UISpriteBatch batch)
 {
     DrawLocalTexture(batch, PxWhite, null, new Vector2((MaxWidth - TitleWidth) / 2, 0), new Vector2(TitleWidth, 40), UIStyle.Current.Bg);
     Background.Visible = true;
     Background.Draw(batch);
     DrawLocalTexture(batch, Grad, null, new Vector2((MaxWidth - Width) / 2, 54), new Vector2((Width / (float)Grad.Width) * SelectPct, 66), Color.White);
     Background.Visible = false;
     base.Draw(batch);
 }
示例#36
0
        private UIImage Scale(UIImage image, SizeF size)
        {
            UIGraphics.BeginImageContext(size);
            image.Draw(new RectangleF(new PointF(0, 0), size));
            var ret = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(ret);
        }
示例#37
0
		private UIImage ResizeImage (UIImage view)
		{
			UIImage resultImage = null;

			var newSize = new SizeF (view.Size.Width / 2, view.Size.Height / 2);
			UIGraphics.BeginImageContext (newSize);
			view.Draw (new RectangleF (0, 0, newSize.Width, newSize.Height));
			resultImage = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();

			return resultImage;
		}
		// crop the image, without resizing
		UIImage CropImage(UIImage sourceImage, RectangleF rect)
		{
			var imgSize = sourceImage.Size;
			UIGraphics.BeginImageContext(new SizeF(rect.Width, rect.Height));
			var context = UIGraphics.GetCurrentContext();
			var clippedRect = new RectangleF(0, 0, rect.Width, rect.Height);
			context.ClipToRect(clippedRect);
			var drawRect = new RectangleF(-rect.X, -rect.Y, imgSize.Width, imgSize.Height);
			sourceImage.Draw(drawRect);
			var modifiedImage = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();
			return modifiedImage;
		}
		// Child proof the image by rounding the edges of the image
		public static UIImage RemoveSharpEdges (UIImage image)
		{
			if (image == null)
				throw new ArgumentNullException ("image");


			UIGraphics.BeginImageContext (image.Size);
			var c = UIGraphics.GetCurrentContext ();

			c.AddPath (MakeRoundedPath (image.Size.Height));

			image.Draw (new RectangleF (PointF.Empty, image.Size));
			var converted = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();
			return converted;
		}
        public static UIImage ResizeImageToMaximumSize(UIImage sourceImage, float maxWidth, float maxHeight)
        {
            var sourceSize = sourceImage.Size;
                var maxResizeFactor = Math.Min(maxWidth / sourceSize.Width, maxHeight / sourceSize.Height);

            if (maxResizeFactor > 1)
            {
                return sourceImage;
            }

            var width = maxResizeFactor * sourceSize.Width;
                var height = maxResizeFactor * sourceSize.Height;

            UIGraphics.BeginImageContext(new SizeF(width, height));
                	sourceImage.Draw(new RectangleF(0, 0, width, height));
                	var resultImage = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();

            return resultImage;
        }
示例#41
0
文件: GraphicsII.cs 项目: 21Off/21Off
		public static UIImage RemoveSharpEdges (UIImage image, float width, int radius)  
		{  
		    UIGraphics.BeginImageContext (new SizeF (width, width)); 
			//UIGraphics.BeginImageContextWithOptions(new SizeF (width, width), true, 0.0f);
		    var c = UIGraphics.GetCurrentContext ();  

			c.AddPath(MakeRoundedPath(width, radius)); 
			c.Clip();
		      
		    //image.Draw (new PointF (0, 0));
			image.Draw (new RectangleF (0, 0, width, width));
		    var converted = UIGraphics.GetImageFromCurrentImageContext ();  
		    UIGraphics.EndImageContext ();  
		    return converted;  
		}
		void DrawRecipeImage (UIImage image, RectangleF rect)
		{
			// Create a new rect based on the size of the header area
			RectangleF imageRect = RectangleF.Empty;
			
			// Scale the image to fit in the infoRect
			float maxImageDimension = RecipeInfoHeight - Padding * 2;
			float largestImageDimension = Math.Max (image.Size.Width, image.Size.Height);
			float scale = maxImageDimension / largestImageDimension;
			
			imageRect.Size.Width = image.Size.Width * scale;
			imageRect.Size.Height = image.Size.Height * scale;
			
			// Place the image rect at the x,y defined by the argument rect
			imageRect.Location = new PointF (rect.Left + Padding, rect.Top + Padding);
			
			// Ask the image to draw in the image rect
			image.Draw (imageRect);
		}
示例#43
0
        //
        // Centers image, scales and removes borders
        //
        internal static UIImage PrepareForProfileView(UIImage image)
        {
            const int size = 73;
            if (image == null)
                throw new ArgumentNullException ("image");

            UIGraphics.BeginImageContext (new SizeF (73, 73));
            var c = UIGraphics.GetCurrentContext ();

            c.AddPath (largePath);
            c.Clip ();

            // Twitter not always returns squared images, adjust for that.
            var cg = image.CGImage;
            float width = cg.Width;
            float height = cg.Height;
            if (width != height){
                float x = 0, y = 0;
                if (width > height){
                    x = (width-height)/2;
                    width = height;
                } else {
                    y = (height-width)/2;
                    height = width;
                }
                c.ScaleCTM (1, -1);
                using (var copy = cg.WithImageInRect (new RectangleF (x, y, width, height))){
                    c.DrawImage (new RectangleF (0, 0, size, -size), copy);
                }
            } else
                image.Draw (new RectangleF (0, 0, size, size));

            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
示例#44
0
        // Child proof the image by rounding the edges of the image
        internal static UIImage RemoveSharpEdges(UIImage image)
        {
            if (image == null)
                throw new ArgumentNullException ("image");

            UIGraphics.BeginImageContext (new SizeF (48, 48));
            var c = UIGraphics.GetCurrentContext ();

            c.AddPath (smallPath);
            c.Clip ();

            image.Draw (new RectangleF (0, 0, 48, 48));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
示例#45
0
        // Child proof the image by rounding the edges of the image
        internal static UIImage RemoveSharpEdges(UIImage image)
        {
            if (image == null)
            {
                Console.WriteLine("throwing error at remove sharp edges");
                throw new ArgumentNullException ("image");
            }
            var imageSize = Util.IsIpad ? largeSize : smallSize * UIScreen.MainScreen.Scale;
            UIGraphics.BeginImageContext (new SizeF (imageSize, imageSize));
            var c = UIGraphics.GetCurrentContext ();
            if( Util.IsIpad || UIScreen.MainScreen.Scale == 2f)
            c.AddPath (largePath);
            else
                c.AddPath (smallPath);
            c.Clip ();

            image.Draw (new RectangleF (0, 0, imageSize, imageSize));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
示例#46
0
        public static UIImage ResizeImage(UIImage theImage,float width, float height, bool keepRatio)
        {
            if(keepRatio)
            {
                var ratio = theImage.Size.Height / theImage.Size.Width;
                if(height >0)
                    width = height * ratio;
                else
                    height = width * ratio;
            }

            UIGraphics.BeginImageContext (new SizeF (width,height));
            var c = UIGraphics.GetCurrentContext ();

            theImage.Draw (new RectangleF (0, 0, width, height));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
 // resize the image (without trying to maintain aspect ratio)
 static UIImage ResizeImage(UIImage sourceImage, float scale)
 {
     float width = sourceImage.Size.Width * scale;
     float height = sourceImage.Size.Height * scale;
     UIGraphics.BeginImageContext(new SizeF(width, height));
     sourceImage.Draw(new RectangleF(0, 0, width, height));
     var resultImage = UIGraphics.GetImageFromCurrentImageContext();
     UIGraphics.EndImageContext();
     return resultImage;
 }
示例#48
0
		/*
		public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
		{
			base.Selected (dvc, tableView, path);
		}
		*/
		
		public override void Draw (RectangleF bounds, CGContext context, UIView view)
		{			
			UIColor.White.SetFill ();
			context.FillRect (bounds);
			
			RectangleF frame = _inviteButton.Frame;
			frame.X = view.Frame.Width - frame.Width - 10;
			_inviteButton.Frame = frame;
			view.Add(_inviteButton);
			
			if (userImage != null)
			{
				//context.DrawImage(new RectangleF((_height - 35)/2, (_height - 35)/2, 35, 35), userImage.CGImage);
				userImage.Draw(new RectangleF((_height - 35)/2, (_height - 35)/2, 35, 35));
			}
			
			if (graph.ContainsKey(_User.id))
				_User = graph[_User.id];
			
			UIColor.Black.SetColor ();
			if (_User.name != null)
			{
				view.DrawString(_User.name, new RectangleF(50, 5, bounds.Width/2, 10 ), fromFont, UILineBreakMode.TailTruncation);
				
				if (userImage == null)
				{
					userImage = ImageStore.RequestFullPicture((long)_User.id, (long)_User.id, SizeDB.SizeFacebook, this);
					userImage = userImage ?? ImageStore.EmptyProfileImage;
					userImage = UIImageUtils.resizeImage(userImage, new SizeF (35, 35));
					userImage = GraphicsII.RemoveSharpEdges(userImage);
					if (userImage != null)
						userImage.Draw(new RectangleF((_height - 35)/2, (_height - 35)/2, 35, 35));
				}				
			}
			else
			{
				ThreadPool.QueueUserWorkItem(o =>
				{					
					GraphUser gUser = AppDelegateIPhone.AIphone.FacebookServ.GetFriend(_User.id);
					if (gUser == null)
						return;
					
					lock (lock_graph)
					{
						graph[gUser.id] = gUser;
					}
					
					if (gUser.id == _User.id)
					{
						_User = gUser;
						nss.InvokeOnMainThread(()=> view.SetNeedsDisplay());
					}
				});
			}
		}
示例#49
0
        public static UIImage AddImageReflection(UIImage image, float reflectionFraction)
        {
            int reflectionHeight = (int) (image.Size.Height * reflectionFraction);

            // Create a 2 bit CGImage containing a gradient that will be used for masking the
            // main view content to create the 'fade' of the reflection.  The CGImageCreateWithMask
            // function will stretch the bitmap image as required, so we can create a 1 pixel wide gradient

            // gradient is always black and white and the mask must be in the gray colorspace
            var colorSpace = CGColorSpace.CreateDeviceGray ();

            // Creat the bitmap context
            var gradientBitmapContext = new CGBitmapContext (IntPtr.Zero, 1, reflectionHeight, 8, 0, colorSpace, CGImageAlphaInfo.None);

            // define the start and end grayscale values (with the alpha, even though
            // our bitmap context doesn't support alpha the gradien requires it)
            float [] colors = { 0, 1, 1, 1 };

            // Create the CGGradient and then release the gray color space
            var grayScaleGradient = new CGGradient (colorSpace, colors, null);
            colorSpace.Dispose ();

            // create the start and end points for the gradient vector (straight down)
            var gradientStartPoint = new PointF (0, reflectionHeight);
            var gradientEndPoint = PointF.Empty;

            // draw the gradient into the gray bitmap context
            gradientBitmapContext.DrawLinearGradient (grayScaleGradient, gradientStartPoint,
                                                      gradientEndPoint, CGGradientDrawingOptions.DrawsAfterEndLocation);
            grayScaleGradient.Dispose ();

            // Add a black fill with 50% opactiy
            gradientBitmapContext.SetGrayFillColor (0, 0.5f);
            gradientBitmapContext.FillRect (new RectangleF (0, 0, 1, reflectionHeight));

            // conver the context into a CGImage and release the context
            var gradientImageMask = gradientBitmapContext.ToImage ();
            gradientBitmapContext.Dispose ();

            // create an image by masking the bitmap of the mainView content with the gradient view
            // then release the pre-masked content bitmap and the gradient bitmap
            var reflectionImage = image.CGImage.WithMask (gradientImageMask);
            gradientImageMask.Dispose ();

            var size = new SizeF (image.Size.Width, image.Size.Height + reflectionHeight);

            // Use BeginImageContextWithOptions for retina images (only available on is 4.0 and up).
            // http://stackoverflow.com/questions/6965873/drawing-on-the-retina-display-using-coregraphics-image-pixelated
            if (UIScreen.MainScreen.RespondsToSelector(new Selector("scale")))
            {
                UIGraphics.BeginImageContextWithOptions(size, false, UIScreen.MainScreen.Scale);
            }
            else
            {
                UIGraphics.BeginImageContext (size);
            }

            image.Draw (PointF.Empty);
            var context = UIGraphics.GetCurrentContext ();
            context.DrawImage (new RectangleF (0, image.Size.Height, image.Size.Width, reflectionHeight), reflectionImage);

            var result = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            reflectionImage.Dispose ();

            return result;
        }
示例#50
0
 private UIImage CropImage(UIImage sourceImage, int crop_x, int crop_y, int width, int height)
 {
     var imgSize = sourceImage.Size;
     UIGraphics.BeginImageContext(new SizeF(width, height));
     var context = UIGraphics.GetCurrentContext();
     var clippedRect = new RectangleF(0, 0, width, height);
     context.ClipToRect(clippedRect);
     var drawRect = new RectangleF(-crop_x, -crop_y, imgSize.Width, imgSize.Height);
     sourceImage.Draw(drawRect);
     var modifiedImage = UIGraphics.GetImageFromCurrentImageContext();
     UIGraphics.EndImageContext();
     return modifiedImage;
 }
		UIImage ScaleImage(UIImage image)
		{
			//Picking default iPhone 4 size
			var newRect = new RectangleF(0,0, 320f, 480f);
			UIGraphics.BeginImageContextWithOptions(newRect.Size, false, 0.0f);
			image.Draw (newRect);
			var scaledImage = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();

			return scaledImage;
		}
示例#52
0
        internal static UIImage RemoveSharpEdges(UIImage image,float size,float radius)
        {
            if (image == null)
                throw new ArgumentNullException ("image");

            UIGraphics.BeginImageContext (new SizeF (size, size));
            var c = UIGraphics.GetCurrentContext ();

            //if (HighRes)
            //	c.AddPath (largePath);
            //else
                c.AddPath (GraphicsUtil.MakeRoundedPath (size, radius));

            c.Clip ();
            image.Draw (new RectangleF (0, 0, size, size));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
示例#53
0
		public static UIImage BuildCoverFlow(UIImage image, float reflectionFraction)
		{
			int reflectionHeight = (int) (image.Size.Height * reflectionFraction);

			// gradient is always black and white and the mask must be in the gray colorspace
			var colorSpace = CGColorSpace.CreateDeviceGray();

			// Create the bitmap context
			var gradientBitmapContext = new CGBitmapContext (IntPtr.Zero, 1, reflectionHeight, 8, 0, colorSpace, CGImageAlphaInfo.None);

			// define the start and end grayscale values (with the alpha, even though
			// our bitmap context doesn't support alpha the gradien requires it)
			float [] colors = { 0, 1, 1, 1 };

			// Create the CGGradient and then release the gray color space
			var grayScaleGradient = new CGGradient (colorSpace, colors, null);
			colorSpace.Dispose();

			// create the start and end points for the gradient vector (straight down)
			var gradientStartPoint = new PointF (0, reflectionHeight);
			var gradientEndPoint = PointF.Empty;

			// draw the gradient into the gray bitmap context
			gradientBitmapContext.DrawLinearGradient (grayScaleGradient, gradientStartPoint, gradientEndPoint, CGGradientDrawingOptions.DrawsAfterEndLocation);
			grayScaleGradient.Dispose();

			// Add a black fill with 50% opactiy
			gradientBitmapContext.SetFillColor(0, 0.5f);
			gradientBitmapContext.FillRect (new RectangleF (0, 0, 1, reflectionHeight));

            // conver the context into a CGImage and release the context
			var gradientImageMask = gradientBitmapContext.ToImage();
			gradientBitmapContext.Dispose();

			// create an image by masking the bitmap of the mainView content with the gradient view
			// then release the pre-masked content bitmap and the gradient bitmap
			var cgImage = image.CGImage;
			var reflectionImage = cgImage.WithMask(gradientImageMask);
			cgImage.Dispose();
			gradientImageMask.Dispose();

			var size = new SizeF(image.Size.Width, image.Size.Height + reflectionHeight);
			
			UIGraphics.BeginImageContext(size);
			image.Draw(PointF.Empty);
			var context = UIGraphics.GetCurrentContext();
			context.DrawImage(new RectangleF(0, image.Size.Height, image.Size.Width, reflectionHeight), reflectionImage);

			var result = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();
			reflectionImage.Dispose();

			return result;
		}
示例#54
0
			UIImage RenderImageWithShadow (UIImage image, float radius, UIColor color)
			{
				var size = new SizeF (image.Size.Width+8, image.Size.Height+8);
				
				BeginImageContext (size);
				var ctx = UIGraphics.GetCurrentContext ();

				ctx.SaveState ();
				ctx.SetShadowWithColor (new SizeF (1, 1), radius, color.CGColor);
				image.Draw (new PointF (4, 4));
				ctx.RestoreState ();

				image.Draw (new PointF (4, 4));
				
				image = UIGraphics.GetImageFromCurrentImageContext ();

				UIGraphics.EndImageContext ();
				
				return image;
			}
示例#55
0
        internal static UIImage PrepareForUpload(UIImage image)
        {
            if (image == null)
                throw new ArgumentNullException ("image");

            var max = Math.Max(image.Size.Height,image.Size.Width);

            float scale = 1f;
            if(max > width)
                scale = width / max;
            else
                return image;

            UIGraphics.BeginImageContext (new SizeF (image.Size.Width * scale, image.Size.Height * scale));
            var c = UIGraphics.GetCurrentContext ();

            image.Draw (new RectangleF (0, 0, image.Size.Width * scale, image.Size.Height * scale));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
示例#56
0
        // Child proof the image by rounding the edges of the image
        internal static UIImage RemoveSharpEdges(UIImage image)
        {
            if (image == null)
                throw new ArgumentNullException ("image");

            float size = HighRes ? 73 : 48;

            UIGraphics.BeginImageContext (new SizeF (size, size));
            var c = UIGraphics.GetCurrentContext ();

            if (HighRes)
                c.AddPath (largePath);
            else
                c.AddPath (smallPath);

            c.Clip ();

            image.Draw (new RectangleF (0, 0, size, size));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
        UIImage CropImage(UIImage originalImage, RectangleF rect)
        {
            try
            {
                // I found I needed to draw the image to remove rotation
                // I can probably add scaling here as well to keep image
                // sizes at 200 x 200

                UIGraphics.BeginImageContext (originalImage.Size);
                CGContext context = UIGraphics.GetCurrentContext ();

                originalImage.Draw (new PointF ());

                UIImage rotateImage = UIGraphics.GetImageFromCurrentImageContext ();
                {
                    return new UIImage (rotateImage.CGImage.WithImageInRect (rect));
                }
            }
            finally
            {
                UIGraphics.EndImageContext ();
            }
        }
        UIImage PrepareFlickrPhoto(UIImage image, SizeF cropSize)
        {
            // First rescale
            var rect = new RectangleF (0, 0, cropSize.Width, cropSize.Height);
            UIGraphics.BeginImageContext (rect.Size);
            image.Draw (rect);
            var scaledImage = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();

            // Now crop
            var cropRect = new RectangleF ((scaledImage.Size.Width-cropSize.Width)/2,
                                           (scaledImage.Size.Height-cropSize.Height)/2,
                                           cropSize.Width, cropSize.Height);

            UIGraphics.BeginImageContext (cropRect.Size);
            var ctx = UIGraphics.GetCurrentContext ();

            // Compensate for Quartz coordinates
            ctx.TranslateCTM (0.0f, cropRect.Size.Height);
            ctx.ScaleCTM (1, -1);

            // Draw view into context
            ctx.DrawImage (new RectangleF (-cropRect.X, cropRect.Y - (image.Size.Height - cropRect.Size.Height), image.Size.Width, image.Size.Height), image.CGImage);

            // Create UIImage from context
            var newImage = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();

            return newImage;
        }
示例#59
0
        // Prevent accidents by rounding the edges of the image
        internal static UIImage RemoveSharpEdges(UIImage image)
        {
            UIGraphics.BeginImageContext (new SizeF (48, 48));
            var c = UIGraphics.GetCurrentContext ();

            c.BeginPath ();
            c.MoveTo (48, 24);
            c.AddArcToPoint (48, 48, 24, 48, 4);
            c.AddArcToPoint (0, 48, 0, 24, 4);
            c.AddArcToPoint (0, 0, 24, 0, 4);
            c.AddArcToPoint (48, 0, 48, 24, 4);
            c.ClosePath ();
            c.Clip ();

            image.Draw (new PointF (0, 0));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
示例#60
0
		public static UIImage RoundAndSquare(UIImage image, int radius)
		{
			UIGraphics.BeginImageContext(image.Size);
			var c = UIGraphics.GetCurrentContext();
			
			var size = image.Size.Width;
			c.AddPath(MakeRoundedPath(size, radius));
			c.Clip();

			var cg = image.CGImage;
			float width = cg.Width;
			float height = cg.Height;
			if (width != height)
			{
				float x = 0, y = 0;
				if (width > height)
				{
					x = (width-height)/2;
					width = height;
				}
				else 
				{
					y = (height-width)/2;
					height = width;
				}
				
				c.ScaleCTM (1, -1);
				using (var copy = cg.WithImageInRect(new RectangleF (x, y, width, height)))
				{
					c.DrawImage(new RectangleF (0, 0, size, -size), copy);
					cg.Dispose();
				}
			}
			else 
			{
				image.Draw (new RectangleF (0, 0, size, size));
			}
			
			var converted = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();
			return converted;	
		}