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


C# ImageBuffer.GetBuffer方法代码示例

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


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

示例1: DoXBlur

        internal static void DoXBlur(ImageBuffer sourceDest)
        {
            if (sourceDest.BitDepth != 8)
            {
                throw new NotImplementedException("We only work with 8 bit at the moment.");
            }

            int height = sourceDest.Height;
            int width = sourceDest.Width;
            byte[] buffer = sourceDest.GetBuffer();
            byte[] cache = new byte[width];

            for (int y = 0; y < height; y++)
            {
                int offset = sourceDest.GetBufferOffsetY(y);
                for (int x = 0; x < width; x++)
                {
                    cache[x] = buffer[offset + x];
                }

                for (int x = 1; x < width - 1; x++)
                {
                    int newValue = (cache[x - 1] + cache[x] * 2 + cache[x + 1] + 2) / 4; // the + 2 is so that we will round correctly
                    buffer[offset + x] = (byte)newValue;
                }
            }
        }
开发者ID:jeske,项目名称:agg-sharp,代码行数:27,代码来源:Blur.cs

示例2: DoYBlur

        public static void DoYBlur(ImageBuffer sourceDest)
        {
            if (sourceDest.BitDepth != 8)
            {
                throw new NotImplementedException("We only work with 8 bit at the moment.");
            }

            int height = sourceDest.Height;
            int width = sourceDest.Width;
            byte[] buffer = sourceDest.GetBuffer();
            int strideInBytes = sourceDest.StrideInBytes();
            byte[] cache = new byte[height];

            for (int x = 0; x < width; x++)
            {
                int offset = x;
                for (int y = 0; y < height; y++)
                {
                    cache[y] = buffer[offset];
                    offset += strideInBytes;
                }

                offset = x;
                for (int y = 1; y < height - 1; y++)
                {
                    int newValue = (cache[y - 1] + cache[y] * 2 + cache[y + 1] + 2) / 4; // the + 2 is so that we will round correctly
                    buffer[offset] = (byte)newValue;
                    offset += strideInBytes;
                }
            }
        }
开发者ID:jeske,项目名称:agg-sharp,代码行数:31,代码来源:Blur.cs

示例3: DoErode3x3MinValue

		public static void DoErode3x3MinValue(ImageBuffer source, ImageBuffer dest)
		{
			if (source.BitDepth != 32 || dest.BitDepth != 32)
			{
				throw new NotImplementedException("We only work with 32 bit at the moment.");
			}

			if (source.Width != dest.Width || source.Height != dest.Height)
			{
				throw new NotImplementedException("Source and Dest have to be the same size");
			}

			int height = source.Height;
			int width = source.Width;
			int sourceStrideInBytes = source.StrideInBytes();
			int destStrideInBytes = dest.StrideInBytes();
			byte[] sourceBuffer = source.GetBuffer();
			byte[] destBuffer = dest.GetBuffer();

			// This can be made much faster by holding the buffer pointer and offsets better // LBB 2013 06 09
			for (int testY = 1; testY < height - 1; testY++)
			{
				for (int testX = 1; testX < width - 1; testX++)
				{
					RGBA_Bytes minColor = RGBA_Bytes.White;
					int sourceOffset = source.GetBufferOffsetXY(testX, testY - 1);

					// x-1, y-1
					//minColor = MinColor(sourceBuffer, minColor, sourceOffset - 4);
					// x0, y-1
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + 0);
					// x1, y-1
					//minColor = MinColor(sourceBuffer, minColor, sourceOffset + 4);

					// x-1, y0
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes - 4);
					// x0, y0
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes + 0);
					// x+1, y0
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes + 4);

					// x-1, y+1
					//minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes * 2 - 4);
					// x0, y+1
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes * 2 + 0);
					// x+1, y+1
					//minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes * 2 + 4);

					int destOffset = dest.GetBufferOffsetXY(testX, testY);
					destBuffer[destOffset + 2] = minColor.red;
					destBuffer[destOffset + 1] = minColor.green;
					destBuffer[destOffset + 0] = minColor.blue;
					destBuffer[destOffset + 3] = 255;
				}
			}
		}
开发者ID:CNCBrasil,项目名称:agg-sharp,代码行数:56,代码来源:Erode.cs

示例4: DoDilate3x3MaxValue

        public static void DoDilate3x3MaxValue(ImageBuffer source, ImageBuffer dest)
        {
            if (source.BitDepth != 32 || dest.BitDepth != 32)
            {
                throw new NotImplementedException("We only work with 32 bit at the moment.");
            }

            if (source.Width != dest.Width || source.Height != dest.Height)
            {
                throw new NotImplementedException("Source and Dest have to be the same size");
            }

            int height = source.Height;
            int width = source.Width;
            int sourceStrideInBytes = source.StrideInBytes();
            int destStrideInBytes = dest.StrideInBytes();
            byte[] sourceBuffer = source.GetBuffer();
            byte[] destBuffer = dest.GetBuffer();

            for (int testY = 1; testY < height - 1; testY++)
            {
                for (int testX = 1; testX < width - 1; testX++)
                {
                    RGBA_Bytes maxColor = RGBA_Bytes.Black;
                    int sourceOffset = source.GetBufferOffsetXY(testX, testY -1);

                    // x-1, y-1
                    //maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset - 4);
                    // x0, y-1
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + 0);
                    // x1, y-1
                    //maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + 4);

                    // x-1, y0
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes - 4);
                    // x0, y0
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes + 0);
                    // x+1, y0
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes + 4);

                    // x-1, y+1
                    //maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes * 2 - 4);
                    // x0, y+1
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes * 2 + 0);
                    // x+1, y+1
                    //maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes * 2 + 4);

                    int destOffset = dest.GetBufferOffsetXY(testX, testY);
                    destBuffer[destOffset + 2] = maxColor.red;
                    destBuffer[destOffset + 1] = maxColor.green;
                    destBuffer[destOffset + 0] = maxColor.blue;
                    destBuffer[destOffset + 3] = 255;
                }
            }
        }
开发者ID:jeske,项目名称:agg-sharp,代码行数:55,代码来源:Dilate.cs

示例5: DoSubtract

		public static void DoSubtract(ImageBuffer result, ImageBuffer imageToSubtractFrom, ImageBuffer imageToSubtract)
		{
			if (lookupSubtractAndClamp == null)
			{
				CreateLookup();
			}

			if (imageToSubtractFrom.BitDepth != imageToSubtract.BitDepth || imageToSubtract.BitDepth != result.BitDepth)
			{
				throw new NotImplementedException("All the images have to be the same bit depth.");
			}
			if (imageToSubtractFrom.Width != imageToSubtract.Width || imageToSubtractFrom.Height != imageToSubtract.Height
				|| imageToSubtractFrom.Width != result.Width || imageToSubtractFrom.Height != result.Height)
			{
				throw new Exception("All images must be the same size.");
			}

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

							for (int x = 0; x < width; x++)
							{
								resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255]; // add 255 to make sure not < 0
								offset++;
								resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255];
								offset++;
								resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255];
								offset++;
								resultBuffer[offset] = 255;
								offset++;
							}
						}
					}
					break;

				default:
					throw new NotImplementedException();
			}
		}
开发者ID:CNCBrasil,项目名称:agg-sharp,代码行数:49,代码来源:Subtract.cs

示例6: DoThreshold

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

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

							for (int x = 0; x < width; x++)
							{
								if (testFunction(sourceBuffer, offset, threshold))
								{
									resultBuffer[offset + 0] = (byte)255;
									resultBuffer[offset + 1] = (byte)255;
									resultBuffer[offset + 2] = (byte)255;
									resultBuffer[offset + 3] = (byte)255;
								}
								else
								{
									resultBuffer[offset + 0] = (byte)0;
									resultBuffer[offset + 1] = (byte)0;
									resultBuffer[offset + 2] = (byte)0;
									resultBuffer[offset + 3] = (byte)0;
								}
								offset += 4;
							}
						}
					}
					break;

				default:
					throw new NotImplementedException();
			}
		}
开发者ID:CNCBrasil,项目名称:agg-sharp,代码行数:49,代码来源:Threshold.cs

示例7: DoInvertLightness

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

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

							for (int x = 0; x < width; x++)
							{
								RGBA_Bytes color = new RGBA_Bytes(resultBuffer[offset + 2], resultBuffer[offset + 1], resultBuffer[offset + 0], resultBuffer[offset + 3]);
								RGBA_Bytes invertedColor = InvertColor(color);

								resultBuffer[offset + 0] = invertedColor.blue;
								resultBuffer[offset + 1] = invertedColor.green;
								resultBuffer[offset + 2] = invertedColor.blue;
								resultBuffer[offset + 3] = invertedColor.alpha;

								offset += 4;
							}
						}
					}
					break;

				default:
					throw new NotImplementedException();
			}
		}
开发者ID:CNCBrasil,项目名称:agg-sharp,代码行数:43,代码来源:InvertLightness.cs

示例8: DoMultiply

		public static void DoMultiply(ImageBuffer result, ImageBuffer imageA, ImageBuffer imageB)
		{
			if (imageA.BitDepth != imageB.BitDepth || imageB.BitDepth != result.BitDepth)
			{
				throw new NotImplementedException("All the images have to be the same bit depth.");
			}
			if (imageA.Width != imageB.Width || imageA.Height != imageB.Height
				|| 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();
						byte[] imageBBuffer = imageB.GetBuffer();
						for (int y = 0; y < height; y++)
						{
							int offsetA = imageA.GetBufferOffsetY(y);
							int offsetB = imageB.GetBufferOffsetY(y);
							int offsetResult = result.GetBufferOffsetY(y);

							for (int x = 0; x < width; x++)
							{
								resultBuffer[offsetResult++] = (byte)((imageABuffer[offsetA++] * imageBBuffer[offsetB++]) / 255);
								resultBuffer[offsetResult++] = (byte)((imageABuffer[offsetA++] * imageBBuffer[offsetB++]) / 255);
								resultBuffer[offsetResult++] = (byte)((imageABuffer[offsetA++] * imageBBuffer[offsetB++]) / 255);
								resultBuffer[offsetResult++] = 255; offsetA++; offsetB++;
							}
						}
					}
					break;

				default:
					throw new NotImplementedException();
			}
		}
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:42,代码来源:Multiply.cs

示例9: CompareToLionTGA

		public void CompareToLionTGA()
		{
			LionShape lionShape = new LionShape();
			ImageBuffer renderedImage = new ImageBuffer(512, 400, 24, new BlenderBGR());
			byte alpha = (byte)(.1 * 255);
			for (int i = 0; i < lionShape.NumPaths; i++)
			{
				lionShape.Colors[i].Alpha0To255 = alpha;
			}

			Affine transform = Affine.NewIdentity();
			transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
			transform *= Affine.NewTranslation(renderedImage.Width / 2, renderedImage.Height / 2);

			// This code renders the lion:
			VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(lionShape.Path, transform);
			Graphics2D renderer = renderedImage.NewGraphics2D();
			renderer.Clear(new RGBA_Floats(1.0, 1.0, 1.0, 1.0));
			renderer.Render(transformedPathStorage, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);

			ImageTgaIO.Save(renderedImage, "TestOutput.tga");

			Stream imageStream = File.Open("LionRenderMaster.tga", FileMode.Open);
			ImageBuffer masterImage = new ImageBuffer();
			ImageTgaIO.LoadImageData(masterImage, imageStream, 24);

			bool sameWidth = masterImage.Width == renderedImage.Width;
			bool sameHeight = masterImage.Height == renderedImage.Height;
			Assert.IsTrue(sameWidth && sameHeight);
			Assert.IsTrue(masterImage.BitDepth == renderedImage.BitDepth);
			int unused;
			byte[] masterBuffer = masterImage.GetBuffer(out unused);
			byte[] renderedBuffer = renderedImage.GetBuffer(out unused);
			Assert.IsTrue(masterBuffer.Length == renderedBuffer.Length);
			for (int i = 0; i < masterBuffer.Length; i++)
			{
				if (masterBuffer[i] != renderedBuffer[i])
				{
					Assert.IsTrue(false);
				}
			}
		}
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:42,代码来源:LionRenderTest.cs

示例10: DoDilate3x3Binary

        public static void DoDilate3x3Binary(ImageBuffer source, ImageBuffer dest, int threshold)
        {
            if (source.BitDepth != 32 || dest.BitDepth != 32)
            {
                throw new NotImplementedException("We only work with 32 bit at the moment.");
            }

            if (source.Width != dest.Width || source.Height != dest.Height)
            {
                throw new NotImplementedException("Source and Dest have to be the same size");
            }

            int height = source.Height;
            int width = source.Width;
            int sourceStrideInBytes = source.StrideInBytes();
            int destStrideInBytes = dest.StrideInBytes();
            byte[] sourceBuffer = source.GetBuffer();
            byte[] destBuffer = dest.GetBuffer();

            for (int testY = 1; testY < height-1; testY++)
            {
                for (int testX = 1; testX < width - 1; testX++)
                {
                    for (int sourceY = -1; sourceY <= 1; sourceY++)
                    {
                        for (int sourceX = -1; sourceX <= 1; sourceX++)
                        {
                            int sourceOffset = source.GetBufferOffsetXY(testX + sourceX, testY + sourceY);
                            if (sourceBuffer[sourceOffset] > threshold)
                            {
                                int destOffset = dest.GetBufferOffsetXY(testX, testY);
                                destBuffer[destOffset++] = 255;
                                destBuffer[destOffset++] = 255;
                                destBuffer[destOffset++] = 255;
                                destBuffer[destOffset++] = 255;
                            }
                        }
                    }
                }
            }
        }
开发者ID:jeske,项目名称:agg-sharp,代码行数:41,代码来源:Dilate.cs

示例11: DoWhiteToColor

		public static void DoWhiteToColor(ImageBuffer result, ImageBuffer imageA, RGBA_Bytes color)
		{
			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);

							byte amoutOfWhite = imageABuffer[offsetA];

							for (int x = 0; x < width; x++)
							{
								resultBuffer[offsetResult++] = (byte)(color.blue * amoutOfWhite / 255); offsetA++;
                                resultBuffer[offsetResult++] = (byte)(color.green * amoutOfWhite / 255); offsetA++;
								resultBuffer[offsetResult++] = (byte)(color.red * amoutOfWhite / 255); offsetA++;
								resultBuffer[offsetResult++] = imageABuffer[offsetA++];
                            }
						}
					}
					break;

				default:
					throw new NotImplementedException();
			}
		}
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:41,代码来源:WhiteToColor.cs

示例12: UpdateImageBuffer

        internal void UpdateImageBuffer(ImageBuffer destImageBuffer, Bitmap sourceBitmap)
        {
            BitmapData bitmapData = null;
            bool isLocked = false;
            if (destImageBuffer != null)
            {
                if (!isLocked)
                {
                    bitmapData = sourceBitmap.LockBits(new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, sourceBitmap.PixelFormat);
                }
                int destBufferStrideInBytes = destImageBuffer.StrideInBytes();
                int destBufferHeight = destImageBuffer.Height;
                int destBufferWidth = destImageBuffer.Width;
                int destBufferHeightMinusOne = destBufferHeight - 1;
                int bitmapDataStride = bitmapData.Stride;
                int offset;
                byte[] buffer = destImageBuffer.GetBuffer(out offset);
                if (flipY)
                {
                    unsafe
                    {
                        byte* bitmapDataScan0 = (byte*)bitmapData.Scan0;
                        fixed (byte* pDestFixed = &buffer[offset])
                        {
                            byte* pSource = bitmapDataScan0;
                            for (int y = 0; y < destBufferHeight; y++)
                            {
                                byte* pDest = pDestFixed + destBufferStrideInBytes * (destBufferHeight - 1 - y);

                                for (int x = 0; x < destBufferWidth; x++)
                                {
                                    pDest[x * 4 + 0] = pSource[x * 3 + 0];
                                    pDest[x * 4 + 1] = pSource[x * 3 + 1];
                                    pDest[x * 4 + 2] = pSource[x * 3 + 2];
                                    pDest[x * 4 + 3] = 255;
                                }

                                pSource += bitmapDataStride;
                            }
                        }
                    }
                }
                else
                {
                    unsafe
                    {
                        byte* bitmapDataScan0 = (byte*)bitmapData.Scan0;
                        fixed (byte* pDestFixed = &buffer[offset])
                        {
                            byte* pSource = bitmapDataScan0;
                            for (int y = 0; y < destBufferHeight; y++)
                            {
                                byte* pDest = pDestFixed + destBufferStrideInBytes * (y);

                                for (int x = 0; x < destBufferWidth; x++)
                                {
                                    pDest[x * 4 + 0] = pSource[x * 3 + 0];
                                    pDest[x * 4 + 1] = pSource[x * 3 + 1];
                                    pDest[x * 4 + 2] = pSource[x * 3 + 2];
                                    pDest[x * 4 + 3] = 255;
                                }

                                pSource += bitmapDataStride;
                            }
                        }
                    }
                }
                if (!isLocked)
                {
                    sourceBitmap.UnlockBits(bitmapData);
                }
            }
        }
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:73,代码来源:AForgeCamera.cs

示例13: CreatePath

        //路径
        public static CCSprite CreatePath(
            double width, double height,
            string[] paths,
            double contentX, double contentY,
            double contentWidth, double contentHeight,
            CCColor4B fill, CCColor4B stroke,
            double strokeThickness = 1,
            UIGraphic.Stretch stretch = UIGraphic.Stretch.StretchNone
            )
        {
            if (width == 0) width = contentWidth;
            if (height == 0) height = contentHeight;

            ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA());
            Graphics2D g = buffer.NewGraphics2D();

            double scalex = 0;
            double scaley = 0;
            //if (stretch == Stretch.StretchNone) { } else
            if (stretch == UIGraphic.Stretch.StretchFill)
            {
                if (width != contentWidth || height != contentHeight)
                {
                    scalex = width / contentWidth;
                    scaley = height / contentHeight;
                }
            }
            else if (stretch == UIGraphic.Stretch.StretchUniformToFill)
            {
                scalex = scaley = Math.Min(width / contentWidth, height / contentHeight);
            }

            foreach (string path in paths)
            {
                IVertexSource vertexs = MiniLanguage.CreatePathStorage(path);
                if (contentX != 0 || contentY != 0)
                    vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewTranslation(-contentX, -contentY));

                if (scalex != 0 || scaley != 0)
                    vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewScaling(scalex, scaley));

                if (fill.A > 0) g.Render(vertexs, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A));
                if (stroke.A > 0) g.Render(new Stroke(vertexs, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
            }

            Texture2D xnaTexture = XnaTexture((int)width, (int)height);
            xnaTexture.SetData<byte>(buffer.GetBuffer());
            CCTexture2D ccTexture = new CCTexture2D();
            ccTexture.InitWithTexture(xnaTexture);
            return new CCSprite(ccTexture);
        }
开发者ID:liwq-net,项目名称:UIFactory,代码行数:52,代码来源:UIFactory.cs

示例14: Copy8BitDataToImage

        private static void Copy8BitDataToImage(ImageBuffer destImage, Bitmap m_WidowsBitmap)
        {
            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;
                
                Color[] colors = m_WidowsBitmap.Palette.Entries;

                for (int y = 0; y < destImage.Height; y++)
                {
                    sourceIndex = y * bitmapData.Stride;
                    destIndex = destImage.GetBufferOffsetY(destImage.Height - 1 - y);
                    for (int x = 0; x < destImage.Width; x++)
                    {
                        Color color = colors[pSourceBuffer[sourceIndex++]];
                        destBuffer[destIndex++] = color.B;
                        destBuffer[destIndex++] = color.G;
                        destBuffer[destIndex++] = color.R;
                        destBuffer[destIndex++] = color.A;
                    }
                }
            }

            m_WidowsBitmap.UnlockBits(bitmapData);
        }
开发者ID:jeske,项目名称:agg-sharp,代码行数:32,代码来源:ImageIOWindowsPlugin.cs

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


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