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


C# ImageBuffer.SetRecieveBlender方法代码示例

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


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

示例1: LoadImage

		public void LoadImage(string path, ImageBuffer destImage)
		{
			ImageBuffer cachedImage = null;
			if (!cachedImages.TryGetValue(path, out cachedImage))
			{
				using (var imageStream = OpenSteam(path))
				{
					var bitmap = new Bitmap(imageStream);
					cachedImage = new ImageBuffer();
					ImageIOWindowsPlugin.ConvertBitmapToImage(cachedImage, bitmap);
				}
				if (cachedImage.Width < 200 && cachedImage.Height < 200)
				{
					// only cache relatively small images
					cachedImages.Add(path, cachedImage);
				}
			}

			destImage.Allocate(cachedImage.Width, cachedImage.Height, cachedImage.StrideInBytesAbs(), cachedImage.BitDepth);
			destImage.SetRecieveBlender(cachedImage.GetRecieveBlender());
			destImage.CopyFrom(cachedImage);
		}
开发者ID:CNCBrasil,项目名称:agg-sharp,代码行数:22,代码来源:FileSystemStaticData.cs

示例2: ConvertBitmapToImage

        private static bool ConvertBitmapToImage(ImageBuffer destImage, Bitmap m_WidowsBitmap)
        {
            if (m_WidowsBitmap != null)
            {
                switch (m_WidowsBitmap.PixelFormat)
                {
                    case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
                        {
                            destImage.Allocate(m_WidowsBitmap.Width, m_WidowsBitmap.Height, m_WidowsBitmap.Width * 4, 32);
                            if (destImage.GetRecieveBlender() == null)
                            {
                                destImage.SetRecieveBlender(new BlenderBGRA());
                            }

                            BitmapData bitmapData = m_WidowsBitmap.LockBits(new Rectangle(0, 0, m_WidowsBitmap.Width, m_WidowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, m_WidowsBitmap.PixelFormat);
                            int sourceIndex = 0;
                            int destIndex = 0;
                            unsafe
                            {
                                int offset;
                                byte[] destBuffer = destImage.GetBuffer(out offset);
                                byte* pSourceBuffer = (byte*)bitmapData.Scan0;
                                for (int y = 0; y < destImage.Height; y++)
                                {
                                    destIndex = destImage.GetBufferOffsetXY(0, destImage.Height - 1 - y);
                                    for (int x = 0; x < destImage.Width; x++)
                                    {
#if true
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
#else
                                            RGBA_Bytes notPreMultiplied = new RGBA_Bytes(pSourceBuffer[sourceIndex + 0], pSourceBuffer[sourceIndex + 1], pSourceBuffer[sourceIndex + 2], pSourceBuffer[sourceIndex + 3]);
                                            sourceIndex += 4;
                                            RGBA_Bytes preMultiplied = notPreMultiplied.GetAsRGBA_Floats().premultiply().GetAsRGBA_Bytes();
                                            destBuffer[destIndex++] = preMultiplied.blue;
                                            destBuffer[destIndex++] = preMultiplied.green;
                                            destBuffer[destIndex++] = preMultiplied.red;
                                            destBuffer[destIndex++] = preMultiplied.alpha;
#endif
                                    }
                                }
                            }

                            m_WidowsBitmap.UnlockBits(bitmapData);

                            return true;
                        }

                    case System.Drawing.Imaging.PixelFormat.Format24bppRgb:
                        {
                            destImage.Allocate(m_WidowsBitmap.Width, m_WidowsBitmap.Height, m_WidowsBitmap.Width * 4, 32);

                            BitmapData bitmapData = m_WidowsBitmap.LockBits(new Rectangle(0, 0, m_WidowsBitmap.Width, m_WidowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, m_WidowsBitmap.PixelFormat);
                            int sourceIndex = 0;
                            int destIndex = 0;
                            unsafe
                            {
                                int offset;
                                byte[] destBuffer = destImage.GetBuffer(out offset);
                                byte* pSourceBuffer = (byte*)bitmapData.Scan0;
                                for (int y = 0; y < destImage.Height; y++)
                                {
                                    sourceIndex = y * bitmapData.Stride;
                                    destIndex = destImage.GetBufferOffsetXY(0, destImage.Height - 1 - y);
                                    for (int x = 0; x < destImage.Width; x++)
                                    {
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = 255;
                                    }
                                }
                            }

                            m_WidowsBitmap.UnlockBits(bitmapData);
                            return true;
                        }

                    case System.Drawing.Imaging.PixelFormat.Format8bppIndexed:
                        {
                            Copy8BitDataToImage(destImage, m_WidowsBitmap);
                            return true;
                        }

                    default:
                        throw new System.NotImplementedException();
                }

            }
            return false;
        }
开发者ID:jeske,项目名称:agg-sharp,代码行数:93,代码来源:ImageIOWindowsPlugin.cs

示例3: DoAllWhite

		public static void DoAllWhite(ImageBuffer result, ImageBuffer imageA)
		{
			if (imageA.BitDepth != result.BitDepth)
			{
				throw new NotImplementedException("All the images have to be the same bit depth.");
			}
			if (imageA.Width != result.Width || imageA.Height != result.Height)
			{
				throw new Exception("All images must be the same size.");
			}

			switch (imageA.BitDepth)
			{
				case 32:
					{
						int height = imageA.Height;
						int width = imageA.Width;
						byte[] resultBuffer = result.GetBuffer();
						byte[] imageABuffer = imageA.GetBuffer();
						for (int y = 0; y < height; y++)
						{
							int offsetA = imageA.GetBufferOffsetY(y);
							int offsetResult = result.GetBufferOffsetY(y);

							for (int x = 0; x < width; x++)
							{
								int alpha = imageABuffer[offsetA+3];
								if (alpha > 0)
								{
									resultBuffer[offsetResult++] = (byte)255; offsetA++;
									resultBuffer[offsetResult++] = (byte)255; offsetA++;
									resultBuffer[offsetResult++] = (byte)255; offsetA++;
									resultBuffer[offsetResult++] = (byte)alpha; offsetA++;
								}
								else
								{
									resultBuffer[offsetResult++] = (byte)0; offsetA++;
									resultBuffer[offsetResult++] = (byte)0; offsetA++;
									resultBuffer[offsetResult++] = (byte)0; offsetA++;
									resultBuffer[offsetResult++] = (byte)0; offsetA++;
								}
							}
						}
						result.SetRecieveBlender(new BlenderPreMultBGRA());
					}
					break;

				default:
					throw new NotImplementedException();
			}
		}
开发者ID:unlimitedbacon,项目名称:MatterControl,代码行数:51,代码来源:PartThumbnailWidget.cs

示例4: BuildImageFromMeshGroups

		private static ImageBuffer BuildImageFromMeshGroups(List<MeshGroup> loadedMeshGroups, string stlHashCode, Point2D size)
		{
			if (loadedMeshGroups != null
				&& loadedMeshGroups.Count > 0
				&& loadedMeshGroups[0].Meshes != null
				&& loadedMeshGroups[0].Meshes[0] != null)
			{
				ImageBuffer tempImage = new ImageBuffer(size.x, size.y);
				Graphics2D partGraphics2D = tempImage.NewGraphics2D();
				partGraphics2D.Clear(new RGBA_Bytes());

				AxisAlignedBoundingBox aabb = loadedMeshGroups[0].GetAxisAlignedBoundingBox();
				for (int meshGroupIndex = 1; meshGroupIndex < loadedMeshGroups.Count; meshGroupIndex++)
				{
					aabb = AxisAlignedBoundingBox.Union(aabb, loadedMeshGroups[meshGroupIndex].GetAxisAlignedBoundingBox());
				}
				double maxSize = Math.Max(aabb.XSize, aabb.YSize);
				double scale = size.x / (maxSize * 1.2);
				RectangleDouble bounds2D = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
				foreach (MeshGroup meshGroup in loadedMeshGroups)
				{
					foreach (Mesh loadedMesh in meshGroup.Meshes)
					{
						PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh,
							new Vector2((size.x / scale - bounds2D.Width) / 2 - bounds2D.Left,
								(size.y / scale - bounds2D.Height) / 2 - bounds2D.Bottom),
							scale, RGBA_Bytes.White);
					}
				}

				if (File.Exists("RunUnitTests.txt"))
				{
					foreach (Mesh loadedMesh in loadedMeshGroups[0].Meshes)
					{
						List<MeshEdge> nonManifoldEdges = loadedMesh.GetNonManifoldEdges();
						if (nonManifoldEdges.Count > 0)
						{
							partGraphics2D.Circle(size.x / 4, size.x / 4, size.x / 8, RGBA_Bytes.Red);
						}
					}
				}

				tempImage.SetRecieveBlender(new BlenderPreMultBGRA());
				AllWhite.DoAllWhite(tempImage);

				// and give it back
				return tempImage;
			}

			return null;
		}
开发者ID:unlimitedbacon,项目名称:MatterControl,代码行数:51,代码来源:PartThumbnailWidget.cs

示例5: LowLevelReadTGABitsFromBuffer

		private static unsafe int LowLevelReadTGABitsFromBuffer(ImageBuffer imageToReadTo, byte[] wholeFileBuffer, int DestBitDepth)
		{
			STargaHeader TargaHeader = new STargaHeader();
			int FileReadOffset;

			if (!ReadTGAInfo(wholeFileBuffer, out TargaHeader))
			{
				return 0;
			}

			// if the frame we are loading is different then the one we have allocated
			// or we don't have any bits allocated

			if ((imageToReadTo.Width * imageToReadTo.Height) != (TargaHeader.Width * TargaHeader.Height))
			{
				imageToReadTo.Allocate(TargaHeader.Width, TargaHeader.Height, TargaHeader.Width * DestBitDepth / 8, DestBitDepth);
			}

			// work out the line width
			switch (imageToReadTo.BitDepth)
			{
				case 24:
					TGABytesPerLine = imageToReadTo.Width * 3;
					if (imageToReadTo.GetRecieveBlender() == null)
					{
						imageToReadTo.SetRecieveBlender(new BlenderBGR());
					}
					break;

				case 32:
					TGABytesPerLine = imageToReadTo.Width * 4;
					if (imageToReadTo.GetRecieveBlender() == null)
					{
						imageToReadTo.SetRecieveBlender(new BlenderBGRA());
					}
					break;

				default:
					throw new System.Exception("Bad bit depth.");
			}

			if (TGABytesPerLine > 0)
			{
				byte[] BufferToDecompressTo = null;
				FileReadOffset = TargaHeaderSize + TargaHeader.PostHeaderSkip;

				if (TargaHeader.ImageType == 10) // 10 is RLE compressed
				{
					BufferToDecompressTo = new byte[TGABytesPerLine * 2];
				}

				// read all the lines *
				for (int i = 0; i < imageToReadTo.Height; i++)
				{
					byte[] BufferToCopyFrom;
					int CopyOffset = 0;

					int CurReadLine;

					// bit 5 tells us if the image is stored top to bottom or bottom to top
					if ((TargaHeader.Descriptor & 0x20) != 0)
					{
						// bottom to top
						CurReadLine = imageToReadTo.Height - i - 1;
					}
					else
					{
						// top to bottom
						CurReadLine = i;
					}

					if (TargaHeader.ImageType == 10) // 10 is RLE compressed
					{
						FileReadOffset = Decompress(BufferToDecompressTo, wholeFileBuffer, FileReadOffset, imageToReadTo.Width, TargaHeader.BPP, CurReadLine);
						BufferToCopyFrom = BufferToDecompressTo;
					}
					else
					{
						BufferToCopyFrom = wholeFileBuffer;
						CopyOffset = FileReadOffset;
					}

					int bufferOffset;
					byte[] imageBuffer = imageToReadTo.GetBuffer(out bufferOffset);

					switch (imageToReadTo.BitDepth)
					{
						case 8:
							switch (TargaHeader.BPP)
							{
								case 24:
									Do24To8Bit(imageBuffer, BufferToCopyFrom, CopyOffset, imageToReadTo.Width, CurReadLine);
									break;

								case 32:
									Do32To8Bit(imageBuffer, BufferToCopyFrom, CopyOffset, imageToReadTo.Width, CurReadLine);
									break;
							}
							break;

//.........这里部分代码省略.........
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:101,代码来源:ImageTgaIO.cs

示例6: NewSubImageReference

		/// <summary>
		/// This will create a new ImageBuffer that references the same memory as the image that you took the sub image from.
		/// It will modify the original main image when you draw to it.
		/// </summary>
		/// <param name="imageContainingSubImage"></param>
		/// <param name="subImageBounds"></param>
		/// <returns></returns>
		public static ImageBuffer NewSubImageReference(IImageByte imageContainingSubImage, RectangleDouble subImageBounds)
		{
			ImageBuffer subImage = new ImageBuffer();
			if (subImageBounds.Left < 0 || subImageBounds.Bottom < 0 || subImageBounds.Right > imageContainingSubImage.Width || subImageBounds.Top > imageContainingSubImage.Height
				|| subImageBounds.Left >= subImageBounds.Right || subImageBounds.Bottom >= subImageBounds.Top)
			{
				throw new ArgumentException("The subImageBounds must be on the image and valid.");
			}
			int left = Math.Max(0, (int)Math.Floor(subImageBounds.Left));
			int bottom = Math.Max(0, (int)Math.Floor(subImageBounds.Bottom));
			int width = Math.Min(imageContainingSubImage.Width - left, (int)subImageBounds.Width);
			int height = Math.Min(imageContainingSubImage.Height - bottom, (int)subImageBounds.Height);
			int bufferOffsetToFirstPixel = imageContainingSubImage.GetBufferOffsetXY(left, bottom);
			subImage.AttachBuffer(imageContainingSubImage.GetBuffer(), bufferOffsetToFirstPixel, width, height, imageContainingSubImage.StrideInBytes(), imageContainingSubImage.BitDepth, imageContainingSubImage.GetBytesBetweenPixelsInclusive());
			subImage.SetRecieveBlender(imageContainingSubImage.GetRecieveBlender());

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


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