当前位置: 首页>>代码示例>>C#>>正文


C# CGBitmapContext.FillRect方法代码示例

本文整理汇总了C#中CGBitmapContext.FillRect方法的典型用法代码示例。如果您正苦于以下问题:C# CGBitmapContext.FillRect方法的具体用法?C# CGBitmapContext.FillRect怎么用?C# CGBitmapContext.FillRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGBitmapContext的用法示例。


在下文中一共展示了CGBitmapContext.FillRect方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawScreen

		protected void DrawScreen ()
		{

			// create our offscreen bitmap context
			// size
			CGSize bitmapSize = new CGSize (imageView.Frame.Size);
			using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) {

				// save the state of the context while we change the CTM
				context.SaveState ();

				// draw our circle
				context.SetFillColor (1, 0, 0, 1);
				context.TranslateCTM (currentLocation.X, currentLocation.Y);
				context.RotateCTM (currentRotation);
				context.ScaleCTM (currentScale, currentScale);
				context.FillRect (new CGRect (-10, -10, 20, 20));

				// restore our transformations
				context.RestoreState ();

				// draw our coordinates for reference
				DrawCoordinateSpace (context);

				// output the drawing to the view
				imageView.Image = UIImage.FromImage (context.ToImage ());
			}
		}
开发者ID:Rajneesh360Logica,项目名称:monotouch-samples,代码行数:28,代码来源:Controller.cs

示例2: AddImageReflection

        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);

            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;
        }
开发者ID:Ryohei-Yoshikawa,项目名称:OpenFlowSharp,代码行数:57,代码来源:ImageUtils.cs

示例3: makeProgressImage

		public static UIImage makeProgressImage(int width, int height, float progress, CGColor baseColor, CGColor topColor)
		{
		   //Create a CGBitmapContext object
		   CGBitmapContext ctx = new CGBitmapContext(IntPtr.Zero, width, height, 8, 4 * width, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst);
		
		   //Draw a rectangle with the base color
		   ctx.SetFillColor(baseColor);
		   ctx.FillRect(new RectangleF(0,0, width, height));
		
		   //Calculate the width of the 2nd rectangle based on the progress
		   float percentWidth = width * progress;
		
		   //Draw the second rectangle with the top color
		   ctx.SetFillColor(topColor);
		   ctx.FillRect(new RectangleF(0, 0, percentWidth, height));
		
		   //return a UIImage object
		   return UIImage.FromImage(ctx.ToImage());
		}		
开发者ID:21Off,项目名称:21Off,代码行数:19,代码来源:UIImageUtils.cs

示例4: MakeEmpty

		static UIImage MakeEmpty ()
		{
			using (var cs = CGColorSpace.CreateDeviceRGB ()){
				using (var bit = new CGBitmapContext (IntPtr.Zero, dimx, dimy, 8, 0, cs, CGImageAlphaInfo.PremultipliedFirst)){
					bit.SetStrokeColor (1, 0, 0, 0.5f);
					bit.FillRect (new RectangleF (0, 0, dimx, dimy));
					
					return UIImage.FromImage (bit.ToImage ());
				}
			}
		}
开发者ID:21Off,项目名称:21Off,代码行数:11,代码来源:PhotoElement.cs

示例5: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			// set the background color of the view to white
			View.BackgroundColor = UIColor.White;
			
			// instantiate a new image view that takes up the whole screen and add it to 
			// the view hierarchy
			RectangleF imageViewFrame = new RectangleF (0, -NavigationController.NavigationBar.Frame.Height, View.Frame.Width, View.Frame.Height);
			imageView = new UIImageView (imageViewFrame);
			View.AddSubview (imageView);
			
			// create our offscreen bitmap context
			// size
			SizeF bitmapSize = new SizeF (View.Frame.Size);
			using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) {

				//==== create a grayscale shadow
				// 1) save graphics state
				context.SaveState ();
				// 2) set shadow context for offset and blur
				context.SetShadow (new SizeF (10, -10), 15);
				// 3) perform your drawing operation
				context.SetFillColor (.3f, .3f, .9f, 1);
				context.FillRect (new RectangleF (100, 600, 300, 250));
				// 4) restore the graphics state
				context.RestoreState ();
				
				//==== create a color shadow
				// 1) save graphics state
				context.SaveState ();
				// 2) set shadow context for offset and blur
				context.SetShadowWithColor(new SizeF (15, -15), 10, UIColor.Blue.CGColor);
				// 3) perform your drawing operation
				context.SelectFont ("Helvetica-Bold", 40, CGTextEncoding.MacRoman);
				context.SetTextDrawingMode (CGTextDrawingMode.Fill);
				string text = "Shadows are fun and easy!";
				context.ShowTextAtPoint (150, 200, text, text.Length);
				// 4) restore the graphics state
				context.RestoreState ();
				
				
				// output the drawing to the view
				imageView.Image = UIImage.FromImage (context.ToImage ());
			}
		}
开发者ID:GSerjo,项目名称:monotouch-samples,代码行数:47,代码来源:Controller.cs

示例6: AdjustImage

		public static UIImage AdjustImage (RectangleF rect, UIImage template, CGBlendMode mode, 
		                                   float red, float green, float blue, float alpha)
		{
			using (var cs = CGColorSpace.CreateDeviceRGB ()) {
				using (var context = new CGBitmapContext (IntPtr.Zero, (int)rect.Width, (int)rect.Height, 8, 
				                                          (int)rect.Height * 4, cs, CGImageAlphaInfo.PremultipliedLast)) {
					
					context.TranslateCTM (0.0f, 0f);
					//context.ScaleCTM(1.0f,-1.0f);
					context.DrawImage (rect, template.CGImage);
					context.SetBlendMode (mode);
					context.ClipToMask (rect, template.CGImage);
					context.SetFillColor (red, green, blue, alpha);
					context.FillRect (rect);
					
					return UIImage.FromImage (context.ToImage ());
				}
			}
		}
开发者ID:21Off,项目名称:21Off,代码行数:19,代码来源:GraphicsII.cs

示例7: Render

        /// <summary>
        /// Render the current complete scene.
        /// </summary>
        void Render()
        {
            try
            {
                //if (Monitor.TryEnter(_cacheRenderer, 10))
                lock(_cacheRenderer)
                {
                    try
                    {
                        // use object
                        var rect = _rect;

                        // create the view.
                        var size = (float)System.Math.Max(_rect.Width, _rect.Height);
                        var view = _cacheRenderer.Create((int)(size * _extra), (int)(size * _extra),
                            this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom),
                            this.MapCenter, _invertX, _invertY, this.MapTilt);
                        if (rect.Width == 0)
                        { // only render if a proper size is known.
                            return;
                        }

                        // calculate width/height.
                        var imageWidth = (int)(size * _extra * _scaleFactor);
                        var imageHeight = (int)(size * _extra * _scaleFactor);

                        // create a new bitmap context.
                        var space = CGColorSpace.CreateDeviceRGB();
                        int bytesPerPixel = 4;
                        int bytesPerRow = bytesPerPixel * imageWidth;
                        int bitsPerComponent = 8;

                        // get old image if available.
                        var image = new CGBitmapContext(null, imageWidth, imageHeight,
                            bitsPerComponent, bytesPerRow,
                            space, // kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast
                            CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Big);

                        long before = DateTime.Now.Ticks;

                        // build the layers list.
                        var layers = new List<Layer>();
                        for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
                        {
                            layers.Add(this.Map[layerIdx]);
                        }

                        // add the internal layer.
                        try
                        {
                            image.SetFillColor(1, 1, 1, 1);
                            image.FillRect(new CGRect(
                                0, 0, imageWidth, imageHeight));

                            // notify the map that the view has changed.
                            var normalView = _cacheRenderer.Create((float)_rect.Width, (float)_rect.Height,
                                this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom),
                                this.MapCenter, _invertX, _invertY, this.MapTilt);
                            this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                                normalView, view);
                            long afterViewChanged = DateTime.Now.Ticks;
                            OsmSharp.Logging.Log.TraceEvent("OsmSharp.iOS.UI.MapView", TraceEventType.Information,
                                "View change took: {0}ms @ zoom level {1}",
                                (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom);

                            float zoomFactor = this.MapZoom;
                            float sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                            // does the rendering.
                            bool complete = _cacheRenderer.Render(new CGContextWrapper(image,
                                new CGRect(0, 0, (int)(size * _extra), (int)(size * _extra))),
                                _map.Projection, layers, view, sceneZoomFactor);

                            long afterRendering = DateTime.Now.Ticks;

                            if (complete)
                            { // there was no cancellation, the rendering completely finished.
                                lock (_bufferSynchronisation)
                                {
                                    if (_onScreenBuffer != null &&
                                        _onScreenBuffer.NativeImage != null)
                                    { // on screen buffer.
                                        _onScreenBuffer.NativeImage.Dispose();
                                    }

                                    // add the newly rendered image again.
                                    _onScreenBuffer = new ImageTilted2D(view.Rectangle,
                                        new NativeImage(image.ToImage()), float.MinValue, float.MaxValue);

                                    // store the previous view.
                                    _previouslyRenderedView = view;
                                }

                                // make sure this view knows that there is a new rendering.
                                this.InvokeOnMainThread(SetNeedsDisplay);
                            }

//.........这里部分代码省略.........
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:101,代码来源:MapView.cs

示例8: Render

        /// <summary>
        /// Render the current complete scene.
        /// </summary>
        void Render()
        {
            try
            {
                lock (_renderSynchronisation)
                {
                    RectangleF rect = _rect;

                    // create the view.
                    View2D view = _cacheRenderer.Create((int)(rect.Width * _extra), (int)(rect.Height * _extra),
                                      this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom),
                                      this.MapCenter, _invertX, _invertY, this.MapTilt);
                    if (rect.Width == 0)
                    { // only render if a proper size is known.
                        return;
                    }

                    // calculate width/height.
                    int imageWidth = (int)(rect.Width * _extra * _scaleFactor);
                    int imageHeight = (int)(rect.Height * _extra * _scaleFactor);

                    // create a new bitmap context.
                    CGColorSpace space = CGColorSpace.CreateDeviceRGB();
                    int bytesPerPixel = 4;
                    int bytesPerRow = bytesPerPixel * imageWidth;
                    int bitsPerComponent = 8;

                    // get old image if available.
                    CGBitmapContext image = new CGBitmapContext(null, imageWidth, imageHeight,
                                                bitsPerComponent, bytesPerRow,
                                                space, // kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast
                                                CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Big);

                    long before = DateTime.Now.Ticks;

                    // build the layers list.
                    var layers = new List<Layer>();
                    for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
                    {
                        layers.Add(this.Map[layerIdx]);
                    }

                    // add the internal layer.
                    try
                    {
                        image.SetRGBFillColor(1, 1, 1, 1);
                        image.FillRect(new RectangleF(
                            0, 0, imageWidth, imageHeight));

                        // notify the map that the view has changed.
                        this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                            view);
                        long afterViewChanged = DateTime.Now.Ticks;
                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                            "View change took: {0}ms @ zoom level {1}",
                            (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom);

                        float sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                        // does the rendering.
                        bool complete = _cacheRenderer.Render(new CGContextWrapper(image,
                                            new RectangleF(0, 0, (int)(rect.Width * _extra), (int)(rect.Height * _extra))),
                                            layers, view, sceneZoomFactor);

                        long afterRendering = DateTime.Now.Ticks;
                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                            "Rendering took: {0}ms @ zoom level {1}",
                            (new TimeSpan(afterRendering - afterViewChanged).TotalMilliseconds), this.MapZoom);

                        if (complete)
                        { // there was no cancellation, the rendering completely finished.
                            lock (_bufferSynchronisation)
                            {
                                if (_onScreenBuffer != null &&
                                    _onScreenBuffer.Tag != null)
                                { // on screen buffer.
                                    (_onScreenBuffer.Tag as CGImage).Dispose();
                                }

                                // add the newly rendered image again.
                                _onScreenBuffer = new ImageTilted2D(view.Rectangle, new byte[0], float.MinValue, float.MaxValue);
                                _onScreenBuffer.Tag = image.ToImage();

                                // store the previous view.
                                _previousRenderedZoom = view;
                            }

                            this.InvokeOnMainThread(InvalidateMap);
                        }

                        long after = DateTime.Now.Ticks;
                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.iOS.UI.MapView", TraceEventType.Information,
                            "Rendering in {0}ms", new TimeSpan(after - before).TotalMilliseconds);
                    }
                    finally
                    {

//.........这里部分代码省略.........
开发者ID:nubix-biz,项目名称:OsmSharp,代码行数:101,代码来源:MapView.cs

示例9: applyMosaic

        static CGImage applyMosaic(int tileSize, List<Color> colorPalette, UIImage resizedImg, Bitmap bitmap)
        {
            // - Parameters
            int width = tileSize; // tile width
            int height = tileSize; // tile height
            int outWidth = (int)(resizedImg.Size.Width - (resizedImg.Size.Width % width)); // Round image size
            int outHeight = (int)(resizedImg.Size.Height - (resizedImg.Size.Height % height));

            // -- Initialize buffer
            CGBitmapContext context = new CGBitmapContext (System.IntPtr.Zero, // data
                                                           (int)outWidth, // width
                                                           (int)outHeight, // height
                                                           8, // bitsPerComponent
                                                           outWidth * 4, // bytesPerRow based on pixel width
                                                           CGColorSpace.CreateDeviceRGB (), // colorSpace
                                                           CGImageAlphaInfo.NoneSkipFirst);

            // bitmapInfo
            for (int yb = 0; yb < outHeight / height; yb++) {
                for (int xb = 0; xb < outWidth / width; xb++) {

                    // -- Do the average colors on the source image for the
                    // corresponding mosaic square
                    int r_avg = 0;
                    int g_avg = 0;
                    int b_avg = 0;
                    for (int y = yb * height; y < (yb * height) + height; y++) {
                        for (int x = xb * width; x < (xb * width) + width; x++) {
                            Color c = bitmap.GetPixel (x, y);
                            // Retrieve color values of the source image
                            r_avg += c.R;
                            g_avg += c.G;
                            b_avg += c.B;
                        }
                    }

                    // Make average of R,G and B on filter size
                    r_avg = r_avg / (width * height);
                    g_avg = g_avg / (width * height);
                    b_avg = b_avg / (width * height);

                    // Find the nearest color in the palette
                    Color mosaicColor = new Color ();
                    double minDistance = int.MaxValue;

                    foreach (Color c in colorPalette) {
                        double distance = Math.Abs (Math.Pow (r_avg - c.R, 2) + Math.Pow (g_avg - c.G, 2) + Math.Pow (b_avg - c.B, 2));
                        if (distance < minDistance) {
                            mosaicColor = c;
                            minDistance = distance;
                        }
                    }

                    // Apply mosaic
                    for (int y = 0; y < height; y++) {
                        for (int x = 0; x < width; x++) {
                            context.SetFillColor (new CGColor (mosaicColor.R / 255f, mosaicColor.G / 255f, mosaicColor.B / 255f));
                            context.FillRect (new RectangleF (xb * width, yb * height, width, height));
                        }
                    }
                }
            }

            //-- image from buffer
            CGImage flippedImage = context.ToImage ();
            context.Dispose ();

            return flippedImage;
        }
开发者ID:valryon,项目名称:pixpuzzle,代码行数:69,代码来源:ImageFilters.cs

示例10: CreateTextBitmapContext

		CGBitmapContext CreateTextBitmapContext (string str, out byte[] bitmapData)
		{
			NSString text = new NSString (str);
			UIFont font = UIFont.FromName ("HelveticaNeue-Light", 128);
			CGSize size = text.StringSize (font);
			int width = (int)size.Width;
			int height = (int)size.Height;
			bitmapData = new byte[256*256*4];
			CGBitmapContext bitmapContext = new CGBitmapContext (bitmapData, 256, 256, 8, 256*4, CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedLast);
			//Console.WriteLine ("bitmap context size: {0} x {1}", bitmapContext.Width, bitmapContext.Height);
			UIGraphics.PushContext (bitmapContext);
			float grayLevel = str == " " ? .8f : 1;
			bitmapContext.SetFillColor(grayLevel, grayLevel, grayLevel, 1);
			bitmapContext.FillRect (new RectangleF (0, 0, 256.0f, 256.0f));
			bitmapContext.SetFillColor(0, 0, 0, 1);

			text.DrawString (new CoreGraphics.CGPoint((256.0f - width) / 2.0f, (256.0f - height) / 2.0f + font.Descender), font);
			UIGraphics.PopContext ();

			return bitmapContext;
		}
开发者ID:ARMoir,项目名称:mobile-samples,代码行数:21,代码来源:EAGLView.cs

示例11: BatteryNinePatchImage

		public BatteryNinePatchImage(UIImage image)
		{
			dataImage = image.CGImage;
			IntPtr dataPointer = Marshal.AllocHGlobal(dataImage.Width * dataImage.Height * 4);
			
			CGBitmapContext context = new CGBitmapContext(dataPointer, dataImage.Width, dataImage.Height,
			                                              dataImage.BitsPerComponent, dataImage.BytesPerRow, dataImage.ColorSpace,
			                                              CGImageAlphaInfo.PremultipliedFirst);
			
			context.SetFillColorWithColor(UIColor.White.CGColor);
			context.FillRect(new RectangleF(0, 0, dataImage.Width, dataImage.Height));
			context.DrawImage(new RectangleF(0, 0, dataImage.Width, dataImage.Height), dataImage);
		
			unsafe
			{
				LineSegment lineSegment = null;
				uint* imagePointer = (uint*) (void*) dataPointer;
				for (int xx = 0; xx < dataImage.Width - 1; xx++, imagePointer++)
				{
					if (xx == 0)
					{
						continue;
					}
					uint thisValue = *imagePointer;
					if (lineSegment != null && (thisValue == BLACK_PIXEL_FULL_ALPHA) == lineSegment.Stretch)
					{
						lineSegment.End = xx;
					}
					else
					{
						lineSegment = new LineSegment();
						_horizontalLineSegments.Add (lineSegment);
						lineSegment.Start = xx;
						lineSegment.End = xx;
						lineSegment.Stretch = thisValue == BLACK_PIXEL_FULL_ALPHA;
					}
				}
				lineSegment = null;
				imagePointer = (uint*) (void*) dataPointer;
				for (int xx = 0; xx < dataImage.Height - 1; xx++, imagePointer += dataImage.Width)
				{
					if (xx == 0)
					{
						continue;
					}
					uint thisValue = *imagePointer;
					if (lineSegment != null && (thisValue == BLACK_PIXEL_FULL_ALPHA) == lineSegment.Stretch)
					{
						lineSegment.End = xx;
					}
					else
					{
						lineSegment = new LineSegment();
						lineSegment.Start = xx;
						lineSegment.End = xx;
						lineSegment.Stretch = thisValue == BLACK_PIXEL_FULL_ALPHA;
						_verticalLineSegments.Add (lineSegment);
					}
				}
			}
			Marshal.FreeHGlobal(dataPointer);
		}
开发者ID:abattery,项目名称:MonoTouch.BatteryNinePatchImage,代码行数:62,代码来源:BatteryNinePatchImage.cs

示例12: GetThumbImage

        /// <summary>
        /// Returns thumb image object for page 
        /// </summary>
        /// <param name="thumbContentSize">Thumb content size</param>
        /// <param name="pageNumber">Page number for what will created image object</param>
        /// <returns>Page image object</returns>
        private static UIImage GetThumbImage(float thumbContentSize, int pageNumber)
        {
            if ((pageNumber <= 0) || (pageNumber > PDFDocument.PageCount)) {
                return null;
            }

            // Calc page view size
            var pageSize = PageContentView.GetPageViewSize(pageNumber);
            if (pageSize.Width % 2 > 0) {
                pageSize.Width--;
            }
            if (pageSize.Height % 2 > 0) {
                pageSize.Height--;
            }

            // Calc target size
            var targetSize = new Size((int)pageSize.Width, (int)pageSize.Height);

            // Draw page on CGImage
            CGImage pageImage;
            using (CGColorSpace rgb = CGColorSpace.CreateDeviceRGB()) {
                using (var context = new CGBitmapContext(null, targetSize.Width, targetSize.Height, 8, 0, rgb, CGBitmapFlags.ByteOrder32Little | CGBitmapFlags.NoneSkipFirst)) {
                    using (var pdfPage = PDFDocument.GetPage(pageNumber)) {
                        // Draw page on custom CGBitmap context
                        var thumbRect = new RectangleF(0.0f, 0.0f, targetSize.Width, targetSize.Height);
                        context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
                        context.FillRect(thumbRect);
                        context.ConcatCTM(pdfPage.GetDrawingTransform(CGPDFBox.Crop, thumbRect, 0, true));
                        context.SetRenderingIntent(CGColorRenderingIntent.Default);
                        context.InterpolationQuality = CGInterpolationQuality.Default;
                        context.DrawPDFPage(pdfPage);
                        // Create CGImage from custom CGBitmap context
                        pageImage = context.ToImage();
                    }
                }
            }
            return UIImage.FromImage(pageImage);
        }
开发者ID:kenLa,项目名称:mTouch-PDFReader,代码行数:44,代码来源:ThumbView.cs

示例13: NinePatchImage

		// create a NinePatch from file
		public NinePatchImage(string fileName, ResizeMethod resizeMethod)
		{
			_resizeMethod = resizeMethod;
			
			const uint BLACK_PIXEL_FULL_ALPHA = 0x000000FF;
			
			// base image
			UIImage ninePatchIamge = UIImage.FromFile(fileName);
			
			// get lower level representaton so we can test pixels for blackness
			CGImage dataImage = ninePatchIamge.CGImage;
			IntPtr dataPointer = Marshal.AllocHGlobal(dataImage.Width * dataImage.Height * 4);

			CGBitmapContext context = new CGBitmapContext(dataPointer, dataImage.Width, dataImage.Height,
				dataImage.BitsPerComponent, dataImage.BytesPerRow, dataImage.ColorSpace,
			    CGImageAlphaInfo.PremultipliedFirst);

			context.SetFillColorWithColor(UIColor.White.CGColor);
			context.FillRect(new RectangleF(0, 0, dataImage.Width, dataImage.Height));
			context.DrawImage(new RectangleF(0, 0, dataImage.Width, dataImage.Height), dataImage);

			int topStart = 0;
			int topEnd = dataImage.Width;
			int leftStart = 0;
			int leftEnd = dataImage.Height;
			int bottomStart = 0;
			int bottomEnd = dataImage.Width;
			int rightStart = 0;
			int rightEnd = dataImage.Height;
			
			bool noPaddingSpecified = false;
			int centerHeight = 0;
			int centerWidth = 0;
			
			unsafe
			{
				// calculate top stretch line
				int firstPixel = dataImage.Width;
				int lastPixel = 0;
				uint* imagePointer = (uint*) (void*) dataPointer;
				for (int xx = 0; xx < dataImage.Width; xx++, imagePointer++)
				{
					uint thisValue = *imagePointer;
					if (*imagePointer == BLACK_PIXEL_FULL_ALPHA)
					{
						if (xx < firstPixel)
							firstPixel = xx;
						if (xx > lastPixel)
							lastPixel = xx;
					}
				}
				topStart = firstPixel;
				topEnd = lastPixel;
				_leftWidth = topStart - 1;
				_rightWidth = (dataImage.Width - 2) - topEnd; // assumes padding lines (-1 if not)!
				centerWidth = (dataImage.Width - 2) - (_leftWidth + _rightWidth);
				
				// calculate left side stretch line
				firstPixel = dataImage.Height;
				lastPixel = 0;
				imagePointer = (uint*) (void*) dataPointer;
				for (int xx = 0; xx < dataImage.Height; xx++, imagePointer += dataImage.Width)
				{
					uint thisValue = *imagePointer;
					if (thisValue == BLACK_PIXEL_FULL_ALPHA)
					{
						if (xx < firstPixel)
							firstPixel = xx;
						if (xx > lastPixel)
							lastPixel = xx;
					}
				}
				leftStart = firstPixel;
				leftEnd = lastPixel;
				_upperHeight = leftStart - 1;
				_lowerHeight = (dataImage.Height - 2) - leftEnd;
				centerHeight = (dataImage.Height - 2) - (_upperHeight + _lowerHeight);
				
				// calculate right side padding line
				firstPixel = dataImage.Height;
				lastPixel = 0;
				imagePointer = ((uint*) (void*) dataPointer) + (dataImage.Width - 1);
				for (int xx = 0; xx < dataImage.Height; xx++, imagePointer += dataImage.Width)
				{
					uint thisValue = *imagePointer;
					if (thisValue == BLACK_PIXEL_FULL_ALPHA)
					{
						if (xx < firstPixel)
							firstPixel = xx;
						if (xx > lastPixel)
							lastPixel = xx;
					}
				}
				if (lastPixel == 0)
				{
					noPaddingSpecified = true;
				}
				rightStart = firstPixel;
				rightEnd = lastPixel;
//.........这里部分代码省略.........
开发者ID:284247028,项目名称:MvvmCross,代码行数:101,代码来源:NinePatch.cs

示例14: MakeEmpty

		public static UIImage MakeEmpty (Size size)
		{
			using (var cs = CGColorSpace.CreateDeviceRGB ()) {
				using (var bit = new CGBitmapContext (IntPtr.Zero, size.Width, size.Height, 8, 0, cs, CGImageAlphaInfo.PremultipliedFirst)) {
					bit.SetStrokeColor (0, 0, 0, 0);
					bit.SetFillColor (1, 1, 1, 1);
					bit.FillRect (new RectangleF (0, 0, size.Width, size.Height));
					
					return UIImage.FromImage (bit.ToImage ());
				}
			}
		}		
开发者ID:21Off,项目名称:21Off,代码行数:12,代码来源:UIImageUtils.cs


注:本文中的CGBitmapContext.FillRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。