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


C# ImageBuffer.MarkImageChanged方法代码示例

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


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

示例1: CreateScaledImage

		public static ImageBuffer CreateScaledImage(ImageBuffer unscaledSourceImage, int width, int height)
		{
			ImageBuffer destImage = new ImageBuffer(width, height, 32, unscaledSourceImage.GetRecieveBlender());

			// If the source image is more than twice as big as our dest image.
			while (unscaledSourceImage.Width > destImage.Width * 2)
			{
				// The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
				// So we scale as many times as we need to get the Image to be the right size.
				// If this were going to be a non-uniform scale we could do the x and y separately to get better results.
				ImageBuffer halfImage = new ImageBuffer(unscaledSourceImage.Width / 2, unscaledSourceImage.Height / 2, 32, unscaledSourceImage.GetRecieveBlender());
				halfImage.NewGraphics2D().Render(unscaledSourceImage, 0, 0, 0, halfImage.Width / (double)unscaledSourceImage.Width, halfImage.Height / (double)unscaledSourceImage.Height);
				unscaledSourceImage = halfImage;
			}

			Graphics2D renderGraphics = destImage.NewGraphics2D();
			renderGraphics.ImageRenderQuality = Graphics2D.TransformQuality.Best;

			renderGraphics.Render(unscaledSourceImage, 0, 0, 0, destImage.Width / (double)unscaledSourceImage.Width, destImage.Height / (double)unscaledSourceImage.Height);

			destImage.MarkImageChanged();

			return destImage;
        }
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:24,代码来源:ImageBuffer.cs

示例2: CopyNoramlBufferToImage

		public void CopyNoramlBufferToImage(ImageBuffer destImage, RectangleInt viewport)
		{
			if (destImage.BitDepth != 32)
			{
				throw new Exception("We can only render to 32 bit dest at the moment.");
			}

			Byte[] destBuffer = destImage.GetBuffer();

			viewport.Bottom = Math.Max(0, Math.Min(destImage.Height, viewport.Bottom));
			viewport.Top = Math.Max(0, Math.Min(destImage.Height, viewport.Top));

#if MULTI_THREAD
			System.Threading.Tasks.Parallel.For(viewport.Bottom, viewport.Height, y => //
#else
			for (int y = viewport.Bottom; y < viewport.Height; y++)
#endif
			{
				for (int x = viewport.Left; x < viewport.Right; x++)
				{
					int bufferOffset = destImage.GetBufferOffsetY(y);

					// we don't need to set this if we are anti-aliased
					int totalOffset = bufferOffset + x * 4;
					destBuffer[totalOffset++] = (byte)((normalBuffer[x][y].x + 1) * 128);
					destBuffer[totalOffset++] = (byte)((normalBuffer[x][y].y + 1) * 128); ;
					destBuffer[totalOffset++] = (byte)((normalBuffer[x][y].z + 1) * 128); ;
					destBuffer[totalOffset] = 255;
				}
			}
#if MULTI_THREAD
);
#endif
			destImage.MarkImageChanged();
		}
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:35,代码来源:RayTracer.cs

示例3: ProcessImage

        public void ProcessImage(ImageBuffer distortedImage, ImageBuffer rectifideImage)
        {
            if (distortedImage.BitDepth != 32 || rectifideImage.BitDepth != 32)
            {
                throw new ArgumentException("Both inputs must be 32 bit.");
            }
            if (distortedImage.Width != width || distortedImage.Height != height || rectifideImage.Width != width || rectifideImage.Height != height)
            {
                throw new ArgumentException("Both inputs must be the right size.");
            }

            byte[] distortedBuffer = distortedImage.GetBuffer();
            byte[] rectifideBuffer = rectifideImage.GetBuffer();

            if (DoBilinearFilter)
            {
                for (int i = 0; i < bilinearDistortedToRectifideOffsetTable.Length / 4; i++)
                {
                    int rectifedBufferIndex = i * 4;
                    int pixelOffset = bilinearDistortedToRectifideOffsetTable[i * 4 + 0] * 4;
                    int weight = bilinearWeightTable[i * 4 + 0];
                    int red = distortedBuffer[pixelOffset + 0] * weight;
                    int green = distortedBuffer[pixelOffset + 1] * weight;
                    int blue = distortedBuffer[pixelOffset + 2] * weight;

                    pixelOffset = bilinearDistortedToRectifideOffsetTable[i * 4 + 1] * 4;
                    weight = bilinearWeightTable[i * 4 + 1];
                    red += distortedBuffer[pixelOffset + 0] * weight;
                    green += distortedBuffer[pixelOffset + 1] * weight;
                    blue += distortedBuffer[pixelOffset + 2] * weight;

                    pixelOffset = bilinearDistortedToRectifideOffsetTable[i * 4 + 2] * 4;
                    weight = bilinearWeightTable[i * 4 + 2];
                    red += distortedBuffer[pixelOffset + 0] * weight;
                    green += distortedBuffer[pixelOffset + 1] * weight;
                    blue += distortedBuffer[pixelOffset + 2] * weight;

                    pixelOffset = bilinearDistortedToRectifideOffsetTable[i * 4 + 3] * 4;
                    weight = bilinearWeightTable[i * 4 + 3];
                    red += distortedBuffer[pixelOffset + 0] * weight;
                    green += distortedBuffer[pixelOffset + 1] * weight;
                    blue += distortedBuffer[pixelOffset + 2] * weight;

                    rectifideBuffer[rectifedBufferIndex + 0] = (byte)(red / blendFractionDenominator);
                    rectifideBuffer[rectifedBufferIndex + 1] = (byte)(green / blendFractionDenominator);
                    rectifideBuffer[rectifedBufferIndex + 2] = (byte)(blue / blendFractionDenominator);
                    rectifideBuffer[rectifedBufferIndex + 3] = 255;
                }
            }
            else
            {
                for (int i = 0; i < bilinearDistortedToRectifideOffsetTable.Length / 4; i++)
                {
                    int rectifedBufferIndex = i * 4;
                    int pixelOffset = bilinearDistortedToRectifideOffsetTable[i * 4] * 4;
                    int red = distortedBuffer[pixelOffset + 0]; ;
                    int green = distortedBuffer[pixelOffset + 1];
                    int blue = distortedBuffer[pixelOffset + 2];
                    rectifideBuffer[rectifedBufferIndex + 0] = (byte)red;
                    rectifideBuffer[rectifedBufferIndex + 1] = (byte)green;
                    rectifideBuffer[rectifedBufferIndex + 2] = (byte)blue;
                    rectifideBuffer[rectifedBufferIndex + 3] = 255;
                }
            }

            rectifideImage.MarkImageChanged();
        }
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:67,代码来源:ImageCorrection.cs

示例4: CopyDepthBufferToImage

		public void CopyDepthBufferToImage(ImageBuffer destImage, RectangleInt viewport)
		{
			if (destImage.BitDepth != 32)
			{
				throw new Exception("We can only render to 32 bit dest at the moment.");
			}

			Byte[] destBuffer = destImage.GetBuffer();

			viewport.Bottom = Math.Max(0, Math.Min(destImage.Height, viewport.Bottom));
			viewport.Top = Math.Max(0, Math.Min(destImage.Height, viewport.Top));

			double minZ = 5000;
			double maxZ = 0;
			for (int y = viewport.Bottom; y < viewport.Height; y++)
			{
				for (int x = viewport.Left; x < viewport.Right; x++)
				{
					double depthAtXY = depthBuffer[x][y];
					if (depthAtXY < 5000)
					{
						minZ = Math.Min(minZ, depthAtXY);
						maxZ = Math.Max(maxZ, depthAtXY);
					}
				}
			}

			double divisor = maxZ - minZ;

#if MULTI_THREAD
			System.Threading.Tasks.Parallel.For(viewport.Bottom, viewport.Height, y => //
#else
            for (int y = viewport.Bottom; y < viewport.Height; y++)
#endif
			{
				for (int x = viewport.Left; x < viewport.Right; x++)
				{
					int bufferOffset = destImage.GetBufferOffsetY(y);

					// we don't need to set this if we are anti-aliased
					int totalOffset = bufferOffset + x * 4;
					double depthXY = depthBuffer[x][y];
					double rangedDepth = (depthXY - minZ) / divisor;
					double clampedDepth = Math.Max(0, Math.Min(255, rangedDepth * 255));
					byte depthColor = (byte)(clampedDepth);
					destBuffer[totalOffset++] = depthColor;
					destBuffer[totalOffset++] = depthColor;
					destBuffer[totalOffset++] = depthColor;
					destBuffer[totalOffset] = 255;
				}
			}
#if MULTI_THREAD
);
#endif
			destImage.MarkImageChanged();
		}
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:56,代码来源:RayTracer.cs


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