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


C# ImageBuffer.Width方法代码示例

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


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

示例1: Save

		static public bool Save(ImageBuffer image, Stream streamToSaveImageDataTo)
		{
			STargaHeader TargaHeader;

			BinaryWriter writerToSaveTo = new BinaryWriter(streamToSaveImageDataTo);

			int SourceDepth = image.BitDepth;

			// make sure there is something to save before opening the file
			if (image.Width <= 0 || image.Height <= 0)
			{
				return false;
			}

			// set up the header
			TargaHeader.PostHeaderSkip = 0;	// no skip after the header
			if (SourceDepth == 8)
			{
				TargaHeader.ColorMapType = 1;		// Color type is Palette
				TargaHeader.ImageType = 9;		// 1 = Palette, 9 = RLE Palette
				TargaHeader.ColorMapStart = 0;
				TargaHeader.ColorMapLength = 256;
				TargaHeader.ColorMapBits = 24;
			}
			else
			{
				TargaHeader.ColorMapType = 0;		// Color type is RGB
#if WRITE_RLE_COMPRESSED
		        TargaHeader.ImageType = 10;		// RLE RGB
#else
				TargaHeader.ImageType = 2;		// RGB
#endif
				TargaHeader.ColorMapStart = 0;
				TargaHeader.ColorMapLength = 0;
				TargaHeader.ColorMapBits = 0;
			}
			TargaHeader.XStart = 0;
			TargaHeader.YStart = 0;
			TargaHeader.Width = (ushort)image.Width;
			TargaHeader.Height = (ushort)image.Height;
			TargaHeader.BPP = (byte)SourceDepth;
			TargaHeader.Descriptor = 0;	// all 8 bits are used for alpha

			TargaHeader.BinaryWrite(writerToSaveTo);

			byte[] pLineBuffer = new byte[image.StrideInBytesAbs() * 2];

			//int BytesToSave;
			switch (SourceDepth)
			{
				case 8:
					/*
				if (image.HasPalette())
				{
					for(int i=0; i<256; i++)
					{
						TGAFile.Write(image.GetPaletteIfAllocated()->pPalette[i * RGB_SIZE + RGB_BLUE]);
						TGAFile.Write(image.GetPaletteIfAllocated()->pPalette[i * RGB_SIZE + RGB_GREEN]);
						TGAFile.Write(image.GetPaletteIfAllocated()->pPalette[i * RGB_SIZE + RGB_RED]);
					}
				}
				else
					 */
					{	// there is no palette for this DIB but we should write something
						for (int i = 0; i < 256; i++)
						{
							writerToSaveTo.Write((byte)i);
							writerToSaveTo.Write((byte)i);
							writerToSaveTo.Write((byte)i);
						}
					}
					for (int i = 0; i < image.Height; i++)
					{
						int bufferOffset;
						byte[] buffer = image.GetPixelPointerY(i, out bufferOffset);
#if WRITE_RLE_COMPRESSED
                    BytesToSave = CompressLine8(pLineBuffer, buffer, bufferOffset, image.Width());
			        writerToSaveTo.Write(pLineBuffer, 0, BytesToSave);
#else
						writerToSaveTo.Write(buffer, bufferOffset, image.Width);
#endif
					}
					break;

				case 24:
					for (int i = 0; i < image.Height; i++)
					{
						int bufferOffset;
						byte[] buffer = image.GetPixelPointerY(i, out bufferOffset);
#if WRITE_RLE_COMPRESSED
                    BytesToSave = CompressLine24(pLineBuffer, buffer, bufferOffset, image.Width());
                    writerToSaveTo.Write(pLineBuffer, 0, BytesToSave);
#else
						writerToSaveTo.Write(buffer, bufferOffset, image.Width * 3);
#endif
					}
					break;

				case 32:
					for (int i = 0; i < image.Height; i++)
//.........这里部分代码省略.........
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:101,代码来源:ImageTgaIO.cs


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