首页 > 其他分享 >【代码块】-图片-获取各像素点

【代码块】-图片-获取各像素点

时间:2023-08-08 23:24:39浏览次数:33  
标签:代码 bytes System bitmap 获取 bmp Copy 像素点 rgbValues

整理代码块

代码块整理后存储,供后期使用

/*
这段代码是用于将图像的像素数据锁定、修改、然后再解锁的操作,以实现对图像像素的直接读写
*/

 private static byte[] LockUnlockBitsExample(Image img)
 {
     // Create a new bitmap. 
     Bitmap bmp = (Bitmap)img;

     // Lock the bitmap's bits. 
     Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
     System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
     // Get the address of the first line. 
     IntPtr ptr = bmpData.Scan0;

     // Declare an array to hold the bytes of the bitmap. 
     int bytes = bmpData.Stride * bmp.Height;
     byte[] rgbValues = new byte[bytes];

     // Copy the RGB values into the array. 
     System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

     // Copy the RGB values back to the bitmap 
     System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);

     // Unlock the bits. 
     bmp.UnlockBits(bmpData);

     return rgbValues;
 }

标签:代码,bytes,System,bitmap,获取,bmp,Copy,像素点,rgbValues
From: https://www.cnblogs.com/Katakana/p/17615676.html

相关文章

  • 【代码块】-CS-复制文件夹及内部
    整理代码块代码块整理后存储,供后期使用///<summary>///复制文件及其内部文件///</summary>///<paramname="sources">源文件</param>///<paramname="dest">目标文件</param>///<paramname="cover">同名是否覆盖</param>......
  • 【代码块】-Helper-GZIP
    整理代码块代码块整理后存储,供后期使用usingSystem;usingSystem.IO;usingSystem.IO.Compression;usingSystem.Text;publicclassGzipHelper{///<summary>///GZIP解压缩///</summary>///<paramname="data"></param>/......
  • 【代码块】-Helper-开机启动
    整理代码块代码块整理后存储,供后期使用usingMicrosoft.Win32;/*这段代码可以用于将一个程序设置为开机启动项,或者从开机启动项中移除*/publicclassStartupHelper{///<summary>///设置开机启动项///</summary>///<paramname="enabled">是否......
  • 【代码块】-控件-双缓冲绘制
    整理代码块代码块整理后存储,供后期使用usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;/*这段代码是用于自定义控件绘图的示例,你可以根据自己的需求进行修改和扩展*/publicclassCustomControl:Control{privateboolIsMouseOn=false;pr......
  • 【代码块】-CS-控件属性和时间
    整理代码块代码块整理后存储,供后期使用//winForm,根据控件的名字获取控件Controlcontrol=Controls.Find("button1",true)[0];//获取属性objecto=control.GetType().GetProperty("PropertyName").GetValue(control,null);//获取事件System.Reflection.EventInfo......
  • 遇到的问题-----网上下载的项目修改代码无效,不能相应的生成相应的页面内容
    最近帮同学改毕业设计  同学在网上下了很多  项目的构造方式真是五花八门  昨天改一个项目的时候竟然遇到很奇葩的情况,我在后台.cs改代码, 打点(.)之后没有相应的变量跳出来供你选择 而且修改.cs中的代码运行后根本没有变化 就算是你写错误的代码照样能......
  • [代码随想录]Day12-二叉树part01
    今天的题目就是二叉树的前中后序遍历,目前只写了递归方法,之后再补迭代方法。题目:144.二叉树的前序遍历思路:前序遍历:根-左-右代码1:递归,递归情况下只需要改变递归的顺序即可实现前中后序遍历。/***Definitionforabinarytreenode.*typeTreeNodestruct{*Va......
  • maven打包跳过test代码几种方式
    maven打包跳过test代码几种方式spring项目处理:<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><skip>true</skip&......
  • 不可错过!12个编写整洁Java代码的最佳实践方法
    在软件开发领域摸爬滚打了这些年之后,通过与各类开发者合作,审查他们所编写的代码所累积的经验,使飞哥对整洁代码的理解和认识有了本质的提升。引用《代码整洁之道》中的一段话,实际上,我们花在阅读代码上的时间远远超过编写代码的时间,这个比例甚至超过10比1。在我们致力于编写新代码的......
  • 如何用 Unity 做出一只赛博宠物(0代码新手向)
    推荐的一些学习资料unity官方文档:Unity用户手册(2019.4LTS)-Unity手册视频教程:https://www.bilibili.com/video/BV1zB4y1C7U9live2d官方文档:https://docs.live2d.com/zh-CHS/cubism-sdk-tutorials/top/https://docs.live2d.com/zh-CHS/cubism-sdk-manual/cubism-sdk-......