zoukankan      html  css  js  c++  java
  • c#载入图片,修改图片的二进制数据

    上图片为rar合并图片,图片另存为后后缀改为rar,可以解压缩出项目。

    private void Form1_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = e.Graphics;
                Bitmap bitmap = new Bitmap("p.png");//如果用png图片,格式是rgb,如果用大小如240,240,格式是rgba
                BitmapData data = bitmap.LockBits(new Rectangle(0, 0, 200, 200), System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat);
                IntPtr start = data.Scan0;
    
                // Declare an array to hold the bytes of the bitmap.
                int bytes = Math.Abs(data.Stride) * bitmap.Height;
                byte[] rgbValues = new byte[bytes];
    
                // Copy the RGB values into the array.
                System.Runtime.InteropServices.Marshal.Copy(start, rgbValues, 0, bytes);
    
                // Set every third value to 255. A 24bpp bitmap will look red.  
                for (int counter = 2; counter < rgbValues.Length; counter += 3)
                    rgbValues[counter] = 255;
    
                // Copy the RGB values back to the bitmap
                System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, start, bytes);
    
                // Unlock the bits.
                bitmap.UnlockBits(data);
    
                g.DrawImage(bitmap, 0, 0, 200, 200);
    
    
            }
  • 相关阅读:
    UVA 1386 Cellular Automaton
    ZOJ 3331 Process the Tasks
    CodeForces 650B Image Preview
    CodeForces 650A Watchmen
    CodeForces 651B Beautiful Paintings
    CodeForces 651A Joysticks
    HUST 1601 Shepherd
    HUST 1602 Substring
    HUST 1600 Lucky Numbers
    POJ 3991 Seinfeld
  • 原文地址:https://www.cnblogs.com/wangjixianyun/p/2835383.html
Copyright © 2011-2022 走看看