首页 > 代码库 > dada
dada
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Drawing.Imaging;using System.Runtime.InteropServices;namespace WindowsFormsApplication2{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void LockUnlockBitsExample(PaintEventArgs e) { //Create a new bitmap Bitmap bmp = new Bitmap("house.jpg"); //Lock the bitmap‘s bits Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat); //Get the address of the fist line IntPtr ptr = bmpData.Scan0; //Declare an array to hold the bytes of the bitmap int bytes = Math.Abs(bmpData.Stride) * bmp.Height; byte[] rgbValues = new byte[bytes]; //Copy the RGB values into the array Marshal.Copy(ptr, rgbValues, 0, bytes); //Set every third value to 255. A 24bpp bitmap will look red //bitmap图像是BGR的方式存储的。 for (int counter = 1; counter < rgbValues.Length; counter += 3) { rgbValues[counter] = 255; } //Copy the RGB values back to the bitmap Marshal.Copy(rgbValues, 0, ptr, bytes); //Unlock the bits bmp.UnlockBits(bmpData); //Draw the modified image e.Graphics.DrawImage(bmp, 0, 150); } private void Form1_Paint(object sender, PaintEventArgs e) { LockUnlockBitsExample(e); } }}
dada
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。