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


C# Bitmap.UnlockBits方法代码示例

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


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

示例1: FindBlackRegionSize

    public static void FindBlackRegionSize(Bitmap source, ref int leftH, ref int leftW, ref int rightH, ref int rightW)
    {
        int i = 0, j = 0;
        int w = source.Width;
        int h = source.Height;

        BitmapData sourceData = source.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

        leftH = leftW = int.MaxValue;
        rightH = rightW = int.MinValue;
        unsafe
        {
            byte* sourcePtr = (byte*)sourceData.Scan0;

            for (i = 0; i < h; ++i)
            {
                for (j = 0; j < w; ++j)
                {
                    if (sourcePtr[i * sourceData.Stride + j * 3] == 0)
                    {
                        if (i < leftH) { leftH = i; }
                        if (i > rightH) { rightH = i; }
                        if (j < leftW) { leftW = j; }
                        if (j > rightW) { rightW = j; }
                    }
                }
            }

            source.UnlockBits(sourceData);
        }
        GC.Collect(0);
    }
开发者ID:jiabailie,项目名称:Digital-Image-Processing,代码行数:32,代码来源:Tailor.cs

示例2: CopyRectangleToPoint

        /// <summary>
        /// Copies the rectangle to point.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="sourceRectangle">The source rectangle.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="destinationPoint">The destination point.</param>
        /// <param name="flip">if set to <c>true</c> [flip].</param>
        public static void CopyRectangleToPoint( this Bitmap source, Rectangle sourceRectangle, Bitmap destination, Point destinationPoint, Palette palette, bool reverseX, bool reverseY )
        {
            BitmapData bmdSource = source.LockBits( new Rectangle( 0, 0, source.Width, source.Height ), ImageLockMode.ReadOnly, source.PixelFormat );
            BitmapData bmdDest = destination.LockBits( new Rectangle( 0, 0, destination.Width, destination.Height ), ImageLockMode.WriteOnly, destination.PixelFormat );

            int width = sourceRectangle.Width;
            int height = sourceRectangle.Height;
            int x = destinationPoint.X;
            int y = destinationPoint.Y;
            CalcOffset calcX = reverseX ?
                (CalcOffset)(col => (width - col - 1)) :
                (CalcOffset)(col => col);
            CalcOffset calcY = reverseY ?
                (CalcOffset)(row => (height - row - 1)) :
                (CalcOffset)(row => row);

            for (int col = 0; col < sourceRectangle.Width; col++)
            {
                for (int row = 0; row < sourceRectangle.Height; row++)
                {
                    int index = bmdSource.GetPixel( col + sourceRectangle.X, row + sourceRectangle.Y );
                    if (palette.Colors[index % 16].A != 0)
                    {
                        bmdDest.SetPixel8bpp(
                            x + calcX( col ),
                            y + calcY( row ),
                            index );
                    }
                }
            }

            source.UnlockBits( bmdSource );
            destination.UnlockBits( bmdDest );
        }
开发者ID:Glain,项目名称:FFTPatcher,代码行数:42,代码来源:ExtensionMethods.cs

示例3: LoadTexture

    public static void LoadTexture()
    {
        Bitmap bitmap=null;
        BitmapData bitmapData=null;

        string[] tx={"relojes.bmp","ford1.bmp","benz1.jpg","motor.bmp","acelera.bmp","papel1.jpg","piso.jpg","madera2.jpg","madera3.jpg","papel1.jpg","Focus.jpg","fordrunner.jpg","mbne.jpg","particle.bmp","benz.jpg"};
        Gl.glEnable(Gl.GL_TEXTURE_2D);
        Gl.glEnable(Gl.GL_DEPTH_TEST);
        //		Gl.gl.Gl.glEnable(Gl.gl.Gl.gl_BLEND);
        //		Gl.gl.Gl.glBlendFunc(Gl.gl.Gl.gl_SRC_ALPHA,Gl.gl.Gl.gl_ONE_MINUS_SRC_ALPHA);
        Rectangle rect;
        texture=new int[tx.Length];
        Gl.glGenTextures(tx.Length, texture);
        for(int i=0; i<tx.Length; i++)
        {
            bitmap = new Bitmap(Application.StartupPath + "\\" + "Textures\\"+tx[i]);
            rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            bitmapData =bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture[i]);
            Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, (int) Gl.GL_RGB8, bitmap.Width, bitmap.Height, Gl.GL_BGR_EXT, Gl.GL_UNSIGNED_BYTE, bitmapData.Scan0);
        }

        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
        Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_DECAL);

        Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);

        bitmap.UnlockBits(bitmapData);
        bitmap.Dispose();
    }
开发者ID:jesantana,项目名称:ConcesionarioVirtual,代码行数:34,代码来源:Otros.cs

示例4: Invert

        public static bool Invert(Bitmap b)
        {
            // GDI+ still lies to us - the return format is BGR, NOT RGB.
            BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            int stride = bmData.Stride;
            System.IntPtr Scan0 = bmData.Scan0;
            unsafe
            {
                byte* p = (byte*)(void*)Scan0;
                int nOffset = stride - b.Width * 3;
                int nWidth = b.Width * 3;
                for (int y = 0; y < b.Height; ++y)
                {
                    for (int x = 0; x < nWidth; ++x)
                    {
                        p[0] = (byte)(255 - p[0]);
                        ++p;
                    }
                    p += nOffset;
                }
            }

            b.UnlockBits(bmData);

            return true;
        }
开发者ID:TechBridgeWorld,项目名称:TactileGraphics,代码行数:27,代码来源:Program.cs

示例5: LoadTexture

        static int LoadTexture(string filename)
        {
            if (String.IsNullOrEmpty(filename))
                throw new ArgumentException(filename);

            Bitmap bmp = new Bitmap(filename);
            BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            bmp.UnlockBits(bmp_data);
        }
开发者ID:KurtLoeffler,项目名称:Envy,代码行数:10,代码来源:EmptyClass.cs

示例6: BitmapToByteArray

    public static byte[] BitmapToByteArray(Bitmap bitmap)
    {
        BitmapData bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
        int numbytes = bmpdata.Stride * bitmap.Height;
        byte[] bytedata = new byte[numbytes];
        IntPtr ptr = bmpdata.Scan0;

        Marshal.Copy(ptr, bytedata, 0, numbytes);

        bitmap.UnlockBits(bmpdata);

        return bytedata;
    }
开发者ID:ylyking,项目名称:AtlasAdjustment,代码行数:13,代码来源:TextureScale.cs

示例7: Process

        public static Bitmap Process(Bitmap image, Rectangle region)
        {
            int startX = region.Left;
            int startY = region.Top;
            int stopX = image.Width - 1;
            int stopY = image.Height - 1;
            if (startX + region.Width < image.Width)
            {
                stopX = startX + region.Width;
            }
            if (startY + region.Height < image.Height)
            {
                stopY = startX + region.Height;
            }

            int numberOfPixels = (stopX - startX) * (stopY - startY);

            Bitmap bitmap = new Bitmap(region.Width, region.Height);
            Graphics g = Graphics.FromImage(bitmap);
            g.DrawImage(image, new Rectangle(0, 0, region.Width, region.Height), region, GraphicsUnit.Pixel);
            ImageStatistics rgbStatistics = new ImageStatistics(bitmap);

            var b = new Bitmap(image);
            BitmapData bmpData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, b.PixelFormat);
            IntPtr ptr = bmpData.Scan0;
            int stride = bmpData.Stride;

            int bytes = Math.Abs(bmpData.Stride) * b.Height;
            byte[] rgbValues = new byte[bytes];

            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

            Parallel.For(startY, stopY, y =>
            {
                for (int x = startX; x < stopX; x++)
                {
                    int i = y * stride + x * 4;

                    //rgbValues[i] = curve[rgbValues[i]];
                    //rgbValues[i + 1] = curve[rgbValues[i + 1]];
                    //rgbValues[i + 2] = curve[rgbValues[i + 2]];
                }
            });

            System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
            b.UnlockBits(bmpData);

            return b;
        }
开发者ID:helenakolodko,项目名称:ImageEditor,代码行数:49,代码来源:PrewittOperator.cs

示例8: Main

    public static void Main(string[] args)
    {
        Console.WriteLine("");
        if (args.Length < 2) usage();

        mapObj map = new mapObj(args[0]);

        Console.WriteLine("# Map layers " + map.numlayers + "; Map name = " + map.name);
        for (int i = 0; i < map.numlayers; i++)
        {
        Console.WriteLine("Layer [" + i + "] name: " + map.getLayer(i).name);
        }

        try
        {
        Bitmap mapImage = new Bitmap(map.width, map.height, PixelFormat.Format32bppRgb);
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        using (imageObj image = map.draw())
        {
            BitmapData bitmapData = mapImage.LockBits(new Rectangle(0, 0, image.width, image.height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
            try
            {
                if (image.getRawPixels(bitmapData.Scan0) == (int)MS_RETURN_VALUE.MS_FAILURE)
                {
                    Console.WriteLine("Unable to get image contents");
                }
            }
            finally
            {
                mapImage.UnlockBits(bitmapData);
            }

            Console.WriteLine("Rendering time: " + stopwatch.ElapsedMilliseconds + "ms");

            mapImage.Save(args[1]);
        }
        }
        catch (Exception ex)
        {
        Console.WriteLine( "\nMessage ---\n{0}", ex.Message );
        Console.WriteLine(
            "\nHelpLink ---\n{0}", ex.HelpLink );
        Console.WriteLine( "\nSource ---\n{0}", ex.Source );
        Console.WriteLine(
            "\nStackTrace ---\n{0}", ex.StackTrace );
        Console.WriteLine(
            "\nTargetSite ---\n{0}", ex.TargetSite );	}
    }
开发者ID:sbrunner,项目名称:mapserver,代码行数:49,代码来源:drawmapGDIPlus.cs

示例9: GetImage

 static Bitmap GetImage(out Bitmap bac)
 {
     bac = new Bitmap(IMAGE);
     BitmapData data_bac = bac.GetBitmapData();
     PointD center = bac.Half();
     double angle = VALUE * 0.004 * Math.PI;
     PointD vector = new PointD(Math.Sin(angle), -Math.Cos(angle));
     Bitmap bmp = SHORT_NEEDLE.Rotate(angle);
     data_bac.Paste(bmp, center.Add(vector, 0.5 * SHORT_NEEDLE.Height) - bmp.Half(), ImagePasteMode.Transparent);
     angle = VALUE * 0.04 * Math.PI;
     vector = new PointD(Math.Sin(angle), -Math.Cos(angle));
     bmp = LONG_NEEDLE.Rotate(angle);
     data_bac.Paste(bmp, center.Add(vector, 0.5 * LONG_NEEDLE.Height) - bmp.Half(), ImagePasteMode.Transparent);
     bac.UnlockBits(data_bac);
     return bac;
 }
开发者ID:fsps60312,项目名称:Digging-Game-2,代码行数:16,代码来源:Altimeter.cs

示例10: Count

    static unsafe Tuple<double, double, double> Count(string file)
    {
        var bmp = new Bitmap(file);
        var rets = new Tuple<double, double, double>[4];
        double x = 0.0, y = 0.0, z = 0.0;

        BitmapData data = bmp.LockBits(new Rectangle(new Point(0, 0), bmp.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
        byte* p = (byte*)data.Scan0.ToPointer();

        int unit_height = data.Height / 4;
        int unit = unit_height * data.Stride;
        Parallel.Invoke(
            () => CountCore(ref rets[0], p, data.Width, unit_height, data.Stride),
            () => CountCore(ref rets[1], p + unit, data.Width, unit_height, data.Stride),
            () => CountCore(ref rets[2], p + 2 * unit, data.Width, unit_height, data.Stride),
            () => CountCore(ref rets[3], p + 3 * unit, data.Width, data.Height - 3 * unit_height, data.Stride)
        );

        bmp.UnlockBits(data);
        foreach (var item in rets)
        {
            x += item.Item1;
            y += item.Item2;
            z += item.Item3;
        }
        /*

        for (int i = 0; i < bmp.Width; i++)
        {
            for (int j = 0; j < bmp.Height; j++)
            {
                Color c = bmp.GetPixel(i, j);
                x += (double)c.R;
                y += (double)c.G;
                z += (double)c.B;
            }
        }
          */

        Console.WriteLine(((int)x).ToString() + "," + ((int)y).ToString() + "," + ((int)z).ToString());
        double area = bmp.Width * bmp.Height;
        return new Tuple<double, double, double>(x/area, y/area, z/area);
    }
开发者ID:n-n-n,项目名称:ImageVideo,代码行数:43,代码来源:Program.cs

示例11: Brightness

    public static bool Brightness(Bitmap b, int nBrightness)
    {
        if (nBrightness < -255 || nBrightness > 255)
            return false;

        // GDI+ still lies to us - the return format is BGR, NOT RGB.
        BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

        int stride = bmData.Stride;
        System.IntPtr Scan0 = bmData.Scan0;

        int nVal = 0;

        unsafe
        {
            byte* p = (byte*)(void*)Scan0;

            int nOffset = stride - b.Width * 3;
            int nWidth = b.Width * 3;

            for (int y = 0; y < b.Height; ++y)
            {
                for (int x = 0; x < nWidth; ++x)
                {
                    nVal = (int)(p[0] + nBrightness);

                    if (nVal < 0) nVal = 0;
                    if (nVal > 255) nVal = 255;

                    p[0] = (byte)nVal;

                    ++p;
                }
                p += nOffset;
            }
        }

        b.UnlockBits(bmData);

        return true;
    }
开发者ID:vantruc,项目名称:skimpt,代码行数:41,代码来源:ImageEffects.cs

示例12: Open

    public Bitmap Open(string fileName, UInt32 frameRate, int width, int height)
    {
        frameRate_ = frameRate;
        width_ = (UInt32)width;
        height_ = (UInt32)height;
        bmp_ = new Bitmap(width, height, PixelFormat.Format24bppRgb);
        BitmapData bmpDat = bmp_.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
        stride_ = (UInt32)bmpDat.Stride;
        bmp_.UnlockBits(bmpDat);
        AVIFileInit();
        int hr = AVIFileOpenW(ref pfile_, fileName, 4097 /* OF_WRITE | OF_CREATE (winbase.h) */, 0);
        if (hr != 0)
        {
            throw new AviException("error for AVIFileOpenW");
        }

        CreateStream();
        SetOptions();

        return bmp_;
    }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:21,代码来源:AviWriter.cs

示例13: AddFrame

    public void AddFrame(Bitmap new_bmp)
    {
        BitmapData bmpDat = new_bmp.LockBits(
          new Rectangle(0, 0, (int)width_, (int)height_), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

        int hr = AVIStreamWrite(psCompressed_, count_, 1,
           bmpDat.Scan0, // pointer to data
           (Int32)(stride_ * height_),
           0, // 16 = AVIIF_KEYFRAMe
           0,
           0);

        if (hr != 0)
        {
            throw new AviException("AVIStreamWrite");
        }

        new_bmp.UnlockBits(bmpDat);

        count_++;
    }
开发者ID:artemisvision,项目名称:PylonVideoCapture,代码行数:21,代码来源:AviWriter.cs

示例14: ImageTailor

    public static Bitmap ImageTailor(Bitmap source, int leftH, int leftW, int rightH, int rightW)
    {
        int i = 0, j = 0, k = 0;
        int h = rightH - leftH + 1;
        int w = rightW - leftW + 1;

        Bitmap tailor = new Bitmap(w, h);

        BitmapData sourceData = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
        BitmapData tailorData = tailor.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

        unsafe
        {
            byte* sourcePtr = (byte*)sourceData.Scan0;
            byte* tailorPtr = (byte*)tailorData.Scan0;

            for (i = 0; i < h; ++i)
            {
                for (j = 0; j < w; ++j)
                {
                    int sCur = (i + leftH) * sourceData.Stride + (j + leftW) * 3;
                    int nCur = i * tailorData.Stride + j * 3;

                    for (k = 0; k < 3; ++k)
                    {
                        tailorPtr[nCur + k] = sourcePtr[sCur + k];
                    }
                }
            }

            source.UnlockBits(sourceData);
            tailor.UnlockBits(tailorData);

            source.Dispose();
        }

        GC.Collect(2);

        return tailor;
    }
开发者ID:jiabailie,项目名称:Digital-Image-Processing,代码行数:40,代码来源:Tailor.cs

示例15: LoadTexture

    public static void LoadTexture()
    {
        Bitmap bitmap=null;
        BitmapData bitmapData=null;

        string[] tx={"cuadro3.jpg"};
        Gl.glEnable(Gl.GL_TEXTURE_2D);
        Gl.glEnable(Gl.GL_DEPTH_TEST);
        //		Gl.glEnable(Gl.GL_BLEND);
        //		Gl.glBlendFunc(Gl.GL_SRC_ALPHA,Gl.GL_ONE_MINUS_SRC_ALPHA);
        Rectangle rect;
        texture=new int[tx.Length];
        Gl.glGenTextures(tx.Length, texture);
        for(int i=0; i<tx.Length; i++)
        {
            bitmap = new Bitmap(Application.StartupPath + "\\" + tx[i]);
            rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            bitmapData =bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture[i]);
            Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, (int) Gl.GL_RGB8, bitmap.Width, bitmap.Height, Gl.GL_BGR_EXT, Gl.GL_UNSIGNED_BYTE, bitmapData.Scan0);
        int x=Gl.glGetError();
            x++;
        }

        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
        Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_MODULATE);

        Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);

        bitmap.UnlockBits(bitmapData);
        bitmap.Dispose();
    }
开发者ID:jesantana,项目名称:MontanaFractales,代码行数:36,代码来源:Otros.cs


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