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


C# CGBitmapContext.SetFillColorWithColor方法代码示例

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


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

示例1: 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

示例2: 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


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