博客
关于我
c# 数字图像处理 基础
阅读量:694 次
发布时间:2019-03-16

本文共 1486 字,大约阅读时间需要 4 分钟。

Bitmap类

Bitmap对象封装了GDI+中的一个位图,此位图由图形图像及其属性的像素数据组成。因此 Bitmap是用于处理由像素数据定义的图像的对象。

Bitmap类类的主要方法和属性如下:

  • Get Pixel方法和 Setpiⅸel方法:获取和设置一个图像的指定像素的颜色
  • Pixelformat属性:返回图像的像素格式。
  • Palette属性:获取或设置图像所使用的颜色调色板。
  • Height属性和 Width属性:返回图像的高度和宽度
  • Lockbits方法和 Unlockbits方法:分别锁定和解锁系统内存中的位图像素。在基于
    像素点的图像处理方法中使用 Lockbits和 Unlockbits是一个很好的方式,这两种方法可以使
    我们通过指定像素的范围来控制位图的任意一部分,从而消除了通过循环对位图的像素逐个
    进行处理的需要。每次调用 Lockbits之后都应该调用一次 Unlockbits

Lockbits方法的定义如下:

public BitmapData LockBits(rectangle rect,ImageLockMode flag,PixelFormat format);

Lockbits矩形参数Rectangle定义了要在系统内存中锁定的位图的一部分;

Image Lockmode枚举提供了对数据的访问方式,表2.1所示是它的成员;

private void Button1_Click(System.Object sender, System.EventArgs e){       try    {           // Retrieve the image.        image1 = new Bitmap(@"C:\Documents and Settings\All Users\"             + @"Documents\My Music\music.bmp", true);        int x, y;        // Loop through the images pixels to reset color.        for(x=0; x

BitmapData类

Bitmapdata对象指定了位图的属性,如下所示。

  • Height属性:被锁定位图的高度
  • Width属性:被锁定位图的宽度
  • PixelFormat属性:数据的实际像素格式
  • Scan0属性:被锁定数组的首字节地数组的地址。如果整个图像被锁定,则是图像Height的第一个字节地址。
  • Stride属性:步幅,也称为扫描宽度

如图所示,数组的宽度并不一定等于图像像素数组的宽度,还有一部分未用区域。这是为了提高效率,系统要确定每行的字节数必须为4的倍数。

例如一幅24位、宽为17个像素的图像,它需要每行占有的空间为51(3×17)个字节,但51不是4的倍数,因此还需要补充1个字节,从而使每行的字节数扩展为52(4x13,即 Stride=52),这样就满足了每行字节数是4的倍数的条件。需要扩展多少个字节不仅是由图像的宽度决定,而且还由图像像素的格式决定。

在这里插入图片描述

Graphics类

Graphics对象是GDI+的关键所在。许多对象都是由 Graphics类表示的,该类定义了绘制和填充图形对象的方法和属性。一个应用程序只要需要进行绘制或着色,它就必须使用Graphics对象。

Graphics g= pic1.CreatGraphic(); g.DrawLine(Pens.Blue,point1,point2);

转载地址:http://lglqz.baihongyu.com/

你可能感兴趣的文章
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
no1
查看>>