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


C# PixelFormat.ToString方法代码示例

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


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

示例1: InvalidPixelFormatException

 public InvalidPixelFormatException(PixelFormat invalid, PixelFormat expected) : base (invalid != PixelFormat.Undefined ?
                                                                                     "PixelFormat " + invalid.ToString() + " is invalid" :
                                                                                     expected != PixelFormat.Undefined ?
                                                                                     "PixelFormat " + expected.ToString() + " expected" :
                                                                                     "Invalid PixelFormat")
 {
 }
开发者ID:JGTM2016,项目名称:bdhero,代码行数:7,代码来源:InvalidPixelFormatException.cs

示例2: DrawingSurface

		public DrawingSurface(int width, int height, PixelFormat pixelFormat) {
			logger.Debug("Initializing DrawingSurface with dimensions ({0},{1}), pixel format {2}", width, height, pixelFormat.ToString());
			Bitmap = new Bitmap(width, height, pixelFormat);
			Width = width;
			Height = height;
			Lock(Bitmap.PixelFormat);
			zBuffer = new short[width * height];
			_heightBuffer = new int[width * height];
			_shadowBuffer = new bool[width * height];
		}
开发者ID:dkeetonx,项目名称:ccmaps-net,代码行数:10,代码来源:DrawingSurface.cs

示例3: GetColorDepthForPixelFormat

 private static int GetColorDepthForPixelFormat(PixelFormat format)
 {
     switch (format)
     {
         case PixelFormat.Format8bppIndexed:
             return 8;
         case PixelFormat.Format16bppRgb555:
             return 15;
         case PixelFormat.Format16bppRgb565:
             return 16;
         case PixelFormat.Format24bppRgb:
             return 24;
         case PixelFormat.Format32bppArgb:
         case PixelFormat.Format32bppRgb:
             return 32;
     }
     throw new AGSEditorException("Invalid pixel format: " + format.ToString());
 }
开发者ID:sonneveld,项目名称:agscj,代码行数:18,代码来源:ImportExport.cs

示例4: ChangePixelFormat

        public void ChangePixelFormat(PixelFormat format)
        {
            if (format == this.Format)
                return;

            bool implemented = false;

            switch (this.Format)
            {
                case PixelFormat.RGB:
                    {
                        switch (format)
                        {
                            case PixelFormat.BGR:
                                this.SwapRedAndBluePixelValues();
                                implemented = true;
                                break;
                        }
                    }
                    break;

                case PixelFormat.RGBA:
                    {
                        switch (format)
                        {
                            case PixelFormat.BGRA:
                                this.SwapRedAndBluePixelValues();
                                implemented = true;
                                break;
                        }
                    }
                    break;

                case PixelFormat.BGR:
                    {
                        switch (format)
                        {
                            case PixelFormat.RGB:
                                this.SwapRedAndBluePixelValues();
                                implemented = true;
                                break;
                        }
                    }
                    break;

                case PixelFormat.BGRA:
                    {
                        switch (format)
                        {
                            case PixelFormat.RGBA:
                                this.SwapRedAndBluePixelValues();
                                implemented = true;
                                break;
                        }
                    }
                    break;
            }

            if (!implemented)
                throw new NotImplementedException($"Conversion from format {this.Format.ToString()} to {format.ToString()} is not implemented.");
        }
开发者ID:smack0007,项目名称:SharpImage,代码行数:61,代码来源:Image.cs

示例5: Save

		private void Save (PixelFormat original, PixelFormat expected, bool exactColorCheck)
		{
			string sOutFile = String.Format ("linerect{0}-{1}.gif", getOutSufix (), expected.ToString ());

			// Save		
			Bitmap bmp = new Bitmap (100, 100, original);
			Graphics gr = Graphics.FromImage (bmp);

			using (Pen p = new Pen (Color.Red, 2)) {
				gr.DrawLine (p, 10.0F, 10.0F, 90.0F, 90.0F);
				gr.DrawRectangle (p, 10.0F, 10.0F, 80.0F, 80.0F);
			}

			try {
				bmp.Save (sOutFile, ImageFormat.Gif);

				// Load
				using (Bitmap bmpLoad = new Bitmap (sOutFile)) {
					Assert.AreEqual (expected, bmpLoad.PixelFormat, "PixelFormat");
					Color color = bmpLoad.GetPixel (10, 10);
					if (exactColorCheck) {
						Assert.AreEqual (Color.FromArgb (255, 255, 0, 0), color, "Red");
					} else {
// FIXME: we don't save a pure red (F8 instead of FF) into the file so the color-check assert will fail
// this is due to libgif's QuantizeBuffer. An alternative would be to make our own that checks if less than 256 colors
// are used in the bitmap (or else use QuantizeBuffer).
						Assert.AreEqual (255, color.A, "A");
						Assert.IsTrue (color.R >= 248, "R");
						Assert.AreEqual (0, color.G, "G");
						Assert.AreEqual (0, color.B, "B");
					}
				}
			}
			finally {
				gr.Dispose ();
				bmp.Dispose ();
				try {
					File.Delete (sOutFile);
				}
				catch {
				}
			}
		}
开发者ID:beamer15,项目名称:mono,代码行数:43,代码来源:GifCodecTest.cs

示例6: Save

		private void Save (PixelFormat original, PixelFormat expected, bool colorCheck) 
		{				
			string sOutFile = String.Format ("linerect{0}-{1}.bmp", getOutSufix (), expected.ToString ());
						
			// Save		
			Bitmap bmp = new Bitmap (100, 100, original);						
			Graphics gr = Graphics.FromImage (bmp);

			using (Pen p = new Pen (Color.BlueViolet, 2)) {
				gr.DrawLine (p, 10.0F, 10.0F, 90.0F, 90.0F);
				gr.DrawRectangle (p, 10.0F, 10.0F, 80.0F, 80.0F);
			}

			try {
				bmp.Save (sOutFile, ImageFormat.Bmp);

				// Load
				using (Bitmap bmpLoad = new Bitmap (sOutFile)) {
					Assert.AreEqual (expected, bmpLoad.PixelFormat, "PixelFormat");
					if (colorCheck) {
						Color color = bmpLoad.GetPixel (10, 10);
						Assert.AreEqual (Color.FromArgb (255, 138, 43, 226), color, "BlueViolet");
					}
				}
			}
			finally {
				gr.Dispose ();
				bmp.Dispose ();
				try {
					File.Delete (sOutFile);
				}
				catch {
				}
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:35,代码来源:TestBmpCodec.cs

示例7: ConvertPixelFormatToBitCount

        /// <summary>Get the count of bits per pixel from a PixelFormat value</summary>
        /// <param name="format">One of the PixelFormat members beginning with "Format..." - all others are not supported</param>
        /// <returns>bit count</returns>
        private Int16 ConvertPixelFormatToBitCount(PixelFormat format)
        {
            String formatName = format.ToString();
            if(formatName.Substring(0, 6) != "Format"){
                throw new Exception("Unknown pixel format: "+formatName);
            }

            formatName = formatName.Substring(6, 2);
            Int16 bitCount = 0;
            if( Char.IsNumber(formatName[1]) ){	//16, 32, 48
                bitCount = Int16.Parse(formatName);
            }else{								//4, 8
                bitCount = Int16.Parse(formatName[0].ToString());
            }

            return bitCount;
        }
开发者ID:svn2github,项目名称:fiddler-plus,代码行数:20,代码来源:VideoStream.cs

示例8: CodeImage

        public unsafe void CodeImage(IntPtr scan0, Rectangle scanArea, Size imageSize, PixelFormat format,
            Stream outStream)
        {
            lock (_imageProcessLock)
            {
                byte* pScan0 = (byte*) scan0.ToInt32();
                if (!outStream.CanWrite)
                    throw new Exception("Must have access to Write in the Stream");

                int stride = 0;
                int rawLength = 0;
                int pixelSize = 0;

                switch (format)
                {
                    case PixelFormat.Format24bppRgb:
                    case PixelFormat.Format32bppRgb:
                        pixelSize = 3;
                        break;
                    case PixelFormat.Format32bppArgb:
                    case PixelFormat.Format32bppPArgb:
                        pixelSize = 4;
                        break;
                    default:
                        throw new NotSupportedException(format.ToString());
                }

                stride = imageSize.Width*pixelSize;
                rawLength = stride*imageSize.Height;

                if (_encodeBuffer == null)
                {
                    this._encodedFormat = format;
                    this._encodedWidth = imageSize.Width;
                    this._encodedHeight = imageSize.Height;
                    this._encodeBuffer = new byte[rawLength];
                    fixed (byte* ptr = _encodeBuffer)
                    {
                        byte[] temp = null;
                        using (Bitmap tmpBmp = new Bitmap(imageSize.Width, imageSize.Height, stride, format, scan0))
                        {
                            temp = _jpgCompression.Compress(tmpBmp);
                        }

                        outStream.Write(BitConverter.GetBytes(temp.Length), 0, 4);
                        outStream.Write(temp, 0, temp.Length);
                        memcpy(new IntPtr(ptr), scan0, (uint) rawLength);
                    }
                    return;
                }

                long oldPos = outStream.Position;
                outStream.Write(new byte[4], 0, 4);
                int totalDataLength = 0;

                if (this._encodedFormat != format)
                    throw new Exception("PixelFormat is not equal to previous Bitmap");

                if (this._encodedWidth != imageSize.Width || this._encodedHeight != imageSize.Height)
                    throw new Exception("Bitmap width/height are not equal to previous bitmap");

                List<Rectangle> blocks = new List<Rectangle>();

                Size s = new Size(scanArea.Width, CheckBlock.Height);
                Size lastSize = new Size(scanArea.Width%CheckBlock.Width, scanArea.Height%CheckBlock.Height);

                int lasty = scanArea.Height - lastSize.Height;
                int lastx = scanArea.Width - lastSize.Width;

                Rectangle cBlock = new Rectangle();
                List<Rectangle> finalUpdates = new List<Rectangle>();

                s = new Size(scanArea.Width, s.Height);
                fixed (byte* encBuffer = _encodeBuffer)
                {
                    var index = 0;

                    for (int y = scanArea.Y; y != scanArea.Height;)
                    {
                        if (y == lasty)
                            s = new Size(scanArea.Width, lastSize.Height);
                        cBlock = new Rectangle(scanArea.X, y, scanArea.Width, s.Height);

                        int offset = (y*stride) + (scanArea.X*pixelSize);
                        if (memcmp(encBuffer + offset, pScan0 + offset, (uint) stride) != 0)
                        {
                            index = blocks.Count - 1;
                            if (blocks.Count != 0 && (blocks[index].Y + blocks[index].Height) == cBlock.Y)
                            {
                                cBlock = new Rectangle(blocks[index].X, blocks[index].Y, blocks[index].Width,
                                    blocks[index].Height + cBlock.Height);
                                blocks[index] = cBlock;
                            }
                            else
                            {
                                blocks.Add(cBlock);
                            }
                        }
                        y += s.Height;
                    }
//.........这里部分代码省略.........
开发者ID:TxBlackWolf,项目名称:xRAT,代码行数:101,代码来源:UnsafeStreamCodec.cs

示例9: Save

		private void Save (PixelFormat original, PixelFormat expected)
		{				
			string sOutFile = String.Format ("linerect{0}-{1}.jpeg", getOutSufix (), expected.ToString ());

			// Save		
			Bitmap bmp = new Bitmap (100, 100, original);						
			Graphics gr = Graphics.FromImage (bmp);

			using (Pen p = new Pen (Color.Red, 2)) {
				gr.DrawLine (p, 10.0F, 10.0F, 90.0F, 90.0F);
				gr.DrawRectangle (p, 10.0F, 10.0F, 80.0F, 80.0F);
			}

			try {
				bmp.Save (sOutFile, ImageFormat.Jpeg);

				// Load			
				using (Bitmap bmpLoad = new Bitmap (sOutFile)) {
					Assert.AreEqual (expected, bmpLoad.PixelFormat, "PixelFormat");
					Color color = bmpLoad.GetPixel (10, 10);
					// by default JPEG isn't lossless - so value is "near" read
					Assert.IsTrue (color.R >= 200, "Red");
					Assert.IsTrue (color.G < 60, "Green");
					Assert.IsTrue (color.B < 60, "Blue");
					Assert.AreEqual (0xFF, color.A, "Alpha");
				}
			}
			finally {
				gr.Dispose ();
				bmp.Dispose ();
				try {
					File.Delete (sOutFile);
				}
				catch {
				}
			}
		}
开发者ID:beamer15,项目名称:mono,代码行数:37,代码来源:TestJpegCodec.cs

示例10: VerifyIsSupported

 private static void VerifyIsSupported(PixelFormat format)
 {
     if (format != PixelFormat.Format24bppRgb &&
         format != PixelFormat.Format32bppArgb &&
         format != PixelFormat.Format8bppIndexed)
     {
         throw new ArgumentException("Unsupported pixel format " + format.ToString(), "PixelFormat");
     }
 }
开发者ID:pauldotknopf,项目名称:Taygeta,代码行数:9,代码来源:PlanarImage.cs

示例11: ConvertPixelFormatToBitCount

		/// <summary>Get the count of bits per pixel from a PixelFormat value</summary>
		/// <param name="format">One of the PixelFormat members beginning with "Format..." - all others are not supported</param>
		/// <returns>bit count</returns>
		private Int16 ConvertPixelFormatToBitCount(PixelFormat format) {
			String formatName = format.ToString();
			if (formatName.Substring(0, 6) != "Format") {
				throw new Exception("Unknown pixel format: " + formatName);
			}
			formatName = formatName.Substring(6, 2);
			return Int16.Parse(Char.IsNumber(formatName[1]) ? formatName : formatName[0].ToString());
		}
开发者ID:paradoxfm,项目名称:ledx2,代码行数:11,代码来源:VideoStream.cs

示例12: GetBytesPerPixel

        /// <summary>
        /// Gets the number of bytes per pixel for a given pixel format.
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public static int GetBytesPerPixel(PixelFormat format)
        {
            switch(format)
            {
                case PixelFormat.Format16bppArgb1555:
                case PixelFormat.Format16bppGrayScale:
                case PixelFormat.Format16bppRgb555:
                case PixelFormat.Format16bppRgb565:
                    throw new NotImplementedException("2 bytes per pixel is not yet supported.");
                    //return 2;

                case PixelFormat.Format24bppRgb:
                    return 3;

                case PixelFormat.Format32bppArgb:
                case PixelFormat.Format32bppPArgb:
                case PixelFormat.Format32bppRgb:
                    return 4;

                default:
                    throw new InvalidOperationException(string.Format("Unrecognized Pixel Format {0}.", format.ToString()));
            }
        }
开发者ID:patricknboyd,项目名称:Steganography,代码行数:28,代码来源:Image.cs

示例13: ConvertPixelFormatToBitCount

        private Int16 ConvertPixelFormatToBitCount(PixelFormat format)
        {
            String formatName = format.ToString();

            formatName = formatName.Substring(6, 2);
            Int16 bitCount = 0;
            if (Char.IsNumber(formatName[1]))
                bitCount = Int16.Parse(formatName);
            else
                bitCount = Int16.Parse(formatName[0].ToString());

            return bitCount;
        }
开发者ID:sakthiiv,项目名称:IHGVM,代码行数:13,代码来源:VideoRepel.cs


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