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


C# Image.GetPixel方法代码示例

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


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

示例1: Image_SetGrayScaleToAlpha

        public void Image_SetGrayScaleToAlpha()
        {
            Map m = new Map(256, 256);
            Image i = new Image(256, 256);
            m.Background = new Color("white");
            m.Render(i);
            i.SetGrayScaleToAlpha();
            Color c = i.GetPixel(0, 0);
            Assert.AreEqual(c.R, 255);
            Assert.AreEqual(c.G, 255);
            Assert.AreEqual(c.B, 255);
            Assert.AreEqual(c.A, 255);

            m.Background = new Color("black");
            m.Render(i);
            i.SetGrayScaleToAlpha();
            Color c1 = i.GetPixel(0, 0);
            Assert.AreEqual(c1.R, 255);
            Assert.AreEqual(c1.G, 255);
            Assert.AreEqual(c1.B, 255);
            Assert.AreEqual(c1.A, 0);

            i.SetGrayScaleToAlpha(new Color("green"));
            Color c2 = i.GetPixel(0, 0);
            Assert.AreEqual(c2.R, 0);
            Assert.AreEqual(c2.G, 128);
            Assert.AreEqual(c2.B, 0);
            Assert.AreEqual(c2.A, 255);
        }
开发者ID:rouen-sk,项目名称:NET-Mapnik,代码行数:29,代码来源:ImageTests.cs

示例2: Image_GetSetPixel

 public void Image_GetSetPixel()
 {
     Image i = new Image(1, 1);
     Color c = i.GetPixel(0, 0);
     Assert.AreEqual(c.ToString(), "rgba(0,0,0,0.0)");
     i.SetPixel(0,0, new Color(255, 255, 255));
     Color c1 = i.GetPixel(0, 0);
     Assert.AreEqual(c1.ToString(), "rgb(255,255,255)");
 }
开发者ID:rouen-sk,项目名称:NET-Mapnik,代码行数:9,代码来源:ImageTests.cs

示例3: Save

        public override void Save(Image i, System.IO.Stream dest)
        {
            MemoryStream m = new MemoryStream();
            m.WriteByte(0);
#warning Change this next byte to 255 if you update Image with UInt64 for width and height.
            m.WriteByte(0);
            m.WriteByte(0);
            m.WriteByte(0); // Write the 8 empty bytes at the start of the file.
            m.WriteByte(0);
            m.WriteByte(0);
            m.WriteByte(0);
            m.WriteByte(0);

            byte[] dat = BitConverter.GetBytes(i.Height); // Write the height.
            m.Write(dat, 0, dat.Length);
            dat = BitConverter.GetBytes(i.Width); // Write the width.
            m.Write(dat, 0, dat.Length);

            // Now to write the actual data.
            Pixel p;
            for (uint x = 0; x < i.Width; x++)
            {
                for (uint y = 0; y < i.Height; y++)
                {
                    p = i.GetPixel(x, y);
                    m.WriteByte(p.R);
                    m.WriteByte(p.G);
                    m.WriteByte(p.B);
                    m.WriteByte(p.A);
                }
            }
            dat = Orvid.Compression.LZMA.Compress(m.GetBuffer());
            dest.WriteByte(255);
            dest.Write(dat, 0, dat.Length);
        }
开发者ID:Orvid,项目名称:Cosmos,代码行数:35,代码来源:OIFSupport.cs

示例4: Load

 public override Image Load(Stream s)
 {
     Tiff tif = Tiff.Open(s);
     FieldValue[] value = tif.GetField(TiffTag.ImageWidth);
     int width = value[0].ToInt();
     value = tif.GetField(TiffTag.ImageLength);
     int height = value[0].ToInt();
     int[] raster = new int[height * width];
     tif.ReadRGBAImage(width, height, raster);
     Image i = new Image(width, height);
     int rgba, rasterOffset;
     byte r, g, b, a;
     for (uint y = 0; y < i.Height; y++)
     {
         rasterOffset = (int)(y * i.Width);
         for (uint x = 0; x < i.Width; x++)
         {
             rgba = raster[rasterOffset++];
             r = (byte)(rgba & 0xff);
             g = (byte)((rgba >> 8) & 0xff);
             b = (byte)((rgba >> 16) & 0xff);
             a = (byte)((rgba >> 24) & 0xff);
             i.SetPixel(x, y, new Pixel(r, g, b, a));
         }
     }
     // Need to flip the image.
     Image i2 = new Image(width, height);
     uint y2 = 0;
     for (uint y = (uint)(i.Height - 1); y >= 0 && y < i.Height; y--)
     {
         for (uint x = 0; x < i.Width; x++)
         {
             i2.SetPixel(x, y2, i.GetPixel(x, y));
         }
         y2++;
     }
     i.Dispose();
     return i2;
 }
开发者ID:Orvid,项目名称:Cosmos,代码行数:39,代码来源:TiffSupport.cs

示例5: Render


//.........这里部分代码省略.........

                tH = mH + (mxY - mY);
                y = mH + -mY;
                img = new Image(tW, tH);


                float f_max = (1 << bdfFontDepth) - 1;
                if (f_max == 0)
                    f_max = 1;

                glyph_box = new BDFParser.Rectangle();
                src = new Vec2();
                dst = new Vec2();

                for (int i = 0; i < charsCount; i++)
                {
                    glyph = bdfFont.getGlyph(chrs[i]);
                    if (glyph == null)
                    {
                        continue;
                    }
                    
                    glyph_box = glyph.getBbx(glyph_box);

                    fHeight = glyph_box.height;
                    fData = glyph.getData();
                    scan = fData.Length / fHeight;

                    fg_r = color.R;
                    fg_g = color.G;
                    fg_b = color.B;

                    //box location
                    bx = x + offset + glyph_box.x;
                    by = y - fHeight - glyph_box.y;

                    for (int k = 0; k < fHeight; k++)
                    {
                        offsetLine = k * scan;
                        for (int j = 0; j < scan; j++)
                        {
                            fPixel = fData[offsetLine + j];
                            if (fPixel != 0)
                            {

                                //pixel location
                                px = bx + j;
                                py = by + k;

                                if (tx != null)
                                {
                                    //src.setLocation(px, py);
                                    //tx.transform(src, dst);
#warning TODO: Add support for this.
                                    //px = dst.X;
                                    //py = dst.Y;
                                }

                                //clip
                                if (clip == null || clip.Contains(px, py))
                                {
                                    //compute color
                                    Pixel bg_color = img.GetPixel((uint)px, (uint)py);

                                    bg_r = bg_color.R;
                                    bg_g = bg_color.G;
                                    bg_b = bg_color.B;

                                    //todo improve this pixel composition

                                    float alpha = fPixel / f_max;

                                    r = bg_r + ((int)((fg_r - bg_r) * alpha)) & 0xFF;
                                    g = bg_g + ((int)((fg_g - bg_g) * alpha)) & 0xFF;
                                    b = bg_b + ((int)((fg_b - bg_b) * alpha)) & 0xFF;

                                    Pixel nw = new Pixel((byte)r, (byte)g, (byte)b, 255);

                                    img.SetPixel((uint)px, (uint)py, nw);

                                    if (x_min > px)
                                        x_min = px;
                                    if (y_min > py)
                                        y_min = py;
                                    if (x_max < px)
                                        x_max = px;
                                    if (y_max < py)
                                        y_max = py;
                                }
                            }
                        }
                    }
                    offset += glyph.getDWidth().width;
                }
                //img = ImageManipulator.Resize(img, new Vec2(img.Width * 8, img.Height * 8), ImageManipulator.ScalingAlgorithm.Bicubic);
                //img = ImageManipulator.Resize(img, Vec2.Zero, ImageManipulator.ScalingAlgorithm.Hq2x);
                //img = ImageManipulator.Resize(img, Vec2.Zero, ImageManipulator.ScalingAlgorithm.Hq4x);
                im.DrawImage(loc, img);
            }
        }
开发者ID:Orvid,项目名称:Cosmos,代码行数:101,代码来源:BDFTextRenderer.cs

示例6: WriteBitmapData

 static void WriteBitmapData(Stream output, Image input)
 {
     int num = 10;
     int num2 = 5;
     int num3 = 0;
     for (int i = 0; i < input.Height; i++)
     {
         for (int j = 0; j < input.Width; j++)
         {
             Pixel pixel = input.GetPixel((uint)j, (uint)i);
             ushort num6 = (ushort)(_colorTable8Bit[pixel.B] << (num3 & 0x1f));
             ushort num7 = (ushort)(_colorTable8Bit[pixel.G] << (num2 & 0x1f));
             ushort num8 = (ushort)(_colorTable8Bit[pixel.R] << (num & 0x1f));
             ushort num9 = (ushort)(((0x8000 | num8) | num7) | num6);
             output.Write(BitConverter.GetBytes(num9), 0, 2);
         }
     }
 }
开发者ID:Orvid,项目名称:Cosmos,代码行数:18,代码来源:VbpSupport.cs

示例7: Update

 public override void Update(Image i)
 {
     for (ushort x = 0; x < i.Width; x++)
     {
         for (ushort y = 0; y < i.Height; y++)
         {
             SetPixel(x, y, i.GetPixel(x, y).ToUInt());
         }
     }
 }
开发者ID:Orvid,项目名称:Cosmos,代码行数:10,代码来源:VMWareSVGAII.cs

示例8: Save

 public static void Save(Image img, Stream dest)
 {
     WriteASCII("/* XPM */\nstatic char * pixmap[] = {\n", dest);
     int height = img.Height;
     int width = img.Width;
     SortedList<int, Pixel> list = new SortedList<int, Pixel>();
     int num3 = 0;
     for (int i = 0; i < width; i++)
     {
         for (int m = 0; m < width; m++)
         {
             Pixel pixel = img.GetPixel((uint)i, (uint)m);
             int key = ColorHash(pixel);
             if (!list.ContainsKey(key))
             {
                 list.Add(key, pixel);
                 num3++;
             }
         }
     }
     int num7 = 0;
     int num8 = 0;
     while (num8 < list.Count)
     {
         num8 += 93;
         num7++;
     }
     WriteASCII("/* width height num_colors chars_per_pixel */\n", dest);
     WriteASCII("\"" + width.ToString() + " " + height.ToString() + " " + num3.ToString() + " " + num7.ToString() + "\",\n", dest);
     Dictionary<int, string> dictionary = new Dictionary<int, string>();
     byte[] ascii = new byte[num7];
     for (int j = 0; j < num7; j++)
     {
         ascii[j] = 0x20;
     }
     ascii[0] = 0x1f;
     WriteASCII("/* colors */\n", dest);
     foreach (KeyValuePair<int, Pixel> pair in list)
     {
         IncrementChars(ascii);
         string str2 = Encoding.ASCII.GetString(ascii);
         Pixel color2 = pair.Value;
         if (color2.A > 0)
         {
             WriteASCII("\"" + str2 + " c #" + color2.R.ToString("x").PadLeft(2, '0') + color2.G.ToString("x").PadLeft(2, '0') + color2.B.ToString("x").PadLeft(2, '0') + "\",\n", dest);
         }
         else
         {
             WriteASCII("\"" + str2 + " c None\",\n", dest);
         }
         dictionary.Add(pair.Key, str2);
     }
     WriteASCII("/* pixels */\n", dest);
     for (int k = 0; k < height; k++)
     {
         string str5 = "\"";
         for (int n = 0; n < width; n++)
         {
             string str6;
             int num13 = ColorHash(img.GetPixel((uint)n, (uint)k));
             if (!dictionary.TryGetValue(num13, out str6))
             {
                 throw new Exception("Colour missing from the stringList, weird");
             }
             str5 = str5 + str6;
         }
         if (k == (height - 1))
         {
             str5 = str5 + "\"\n";
         }
         else
         {
             str5 = str5 + "\",\n";
         }
         WriteASCII(str5, dest);
     }
     WriteASCII("};\n", dest);
 }
开发者ID:ChrisJamesSadler,项目名称:Cosmos,代码行数:78,代码来源:XpmSupport.cs


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