如何操作位图中的象素点??(急)

windcbf 2002-05-20 10:30:53
我要用C#进行数字图象处理,但不知道如何操作位图中的象素点
C#不给指针。

谁做过这方面的尝试,望指教!!
...全文
96 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
windcbf 2002-05-21
  • 打赏
  • 举报
回复
这样看来C#不是适合做图象处理,我觉得Java的swing库和awt库倒是蛮好的。。。。
VegetableBird 2002-05-21
  • 打赏
  • 举报
回复
.Net的应用程序效率都很慢,尤其是GDI+的效率更是蜗牛级的:(

如果应用程序对速度的要求很高,还是推荐使用VC++的本地代码。

我前不久的一个项目也需要大量的图形图象处理,这部分功能我使用的是VC++来实现的,行成一个ATL控件,嵌入.Net的程序中。

即使使用Win32 API对HBITMAP进行操作效果也不好,因为.Net的托管代码机制,在非托管代码和托管代码进行通讯的时候,大量的类型安全检查和转换使效率很低,而且频繁的、大数量的交换会导致不可预期的错误——微软自己都这样说,真是。。。:(
colinfly 2002-05-21
  • 打赏
  • 举报
回复
你可以在unsafe代码中用指针。

------------------------------
我是一只小小鸟
欢迎交流!尽管问我吧,我会帮你解决的!
尽快结帖哦!我是CSDN的菜鸟,我想获得一颗星!支持我吧!
MSN&Mail: ColinFly@hotmail.com
windcbf 2002-05-21
  • 打赏
  • 举报
回复
我想进行图象处理,比如位操作等,用setpixel很慢的
VegetableBird 2002-05-20
  • 打赏
  • 举报
回复
Copied from MSDN Lib For .Net

Bitmap.SetPixel:

设置 Bitmap 对象中指定像素的颜色。

[C#]
[Serializable]
[ComVisible(true)]
public void SetPixel(
int x,
int y,
Color color
);
参数
x
要设置的像素的 x 坐标。
y
要设置的像素的 y 坐标。
color
Color 结构,它表示要分配给指定像素的颜色。
返回值
此方法不返回值。

示例
[Visual Basic, C#] 下面的示例旨在用于 Windows 窗体,它需要 PaintEventArgs e(这是 Paint 事件处理程序的参数)。代码执行下列操作:

创建一个 Bitmap 对象。
将位图中每个像素的颜色设置为黑色。
绘制该位图。
[Visual Basic]
Public Sub SetPixel_Example(e As PaintEventArgs)

' Create a Bitmap object from a file.

Dim myBitmap As New Bitmap("Grapes.jpg")

' Draw myBitmap to the screen.

e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _

myBitmap.Height)

' Set each pixel in myBitmap to black.

Dim Xcount As Integer

For Xcount = 0 To myBitmap.Width - 1

Dim Ycount As Integer

For Ycount = 0 To myBitmap.Height - 1

myBitmap.SetPixel(Xcount, Ycount, Color.Black)

Next Ycount

Next Xcount

' Draw myBitmap to the screen again.

e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _

myBitmap.Height)

End Sub
[C#]
public void SetPixel_Example(PaintEventArgs e)

{

// Create a Bitmap object from a file.

Bitmap myBitmap = new Bitmap("Grapes.jpg");

// Draw myBitmap to the screen.

e.Graphics.DrawImage(

myBitmap,

0,

0,

myBitmap.Width,

myBitmap.Height);

// Set each pixel in myBitmap to black.

for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)

{

for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)

{

myBitmap.SetPixel(Xcount, Ycount, Color.Black);

}

}

// Draw myBitmap to the screen again.

e.Graphics.DrawImage(

myBitmap,

myBitmap.Width,

0,

myBitmap.Width,

myBitmap.Height);

}

CForce 2002-05-20
  • 打赏
  • 举报
回复
好像只能靠api吧,跟指针有什么关系?

110,500

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧