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


C# ImageBuffer.Allocate方法代码示例

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


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

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


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