注册 | 登录 | 设为首页 | 加入收藏
您当前的位置:飞翔学院-IT中国 → 编程开发.Net/C# → 文章内容

.Net 开发 Windows Mobile

作者:佚名 来源:本站整理 发布时间:2008-5-22 13:58:44
bValues[(y * image.Width + x) * 3 + 1] = cIn.G;

rgbValues[(y * image.Width + x) * 3 + 2] = cIn.R;

}



public static implicit operator Image(FastBitmap bmp)

{

return bmp.image;

}



public static implicit operator Bitmap(FastBitmap bmp)

{

return bmp.image;

}



public void LockPixels()

{

LockPixels(new Rectangle(0, 0, image.Width, image.Height));

}



private void LockPixels(Rectangle area)

{

if (locked)

return;

locked = true;

bitmapData = image.LockBits(area, ImageLockMode.ReadWrite,

PixelFormat.Format24bppRgb);

IntPtr ptr = bitmapData.Scan0;

int stride = bitmapData.Stride;

int numBytes = image.Width * image.Height * 3;

rgbValues = new byte[numBytes];

Marshal.Copy(ptr, rgbValues, 0, numBytes);

}



public void UnlockPixels()

{

if (!locked)

return;

locked = false;

Marshal.Copy(rgbValues, 0, bitmapData.Scan0, image.Width * image.Height * 3);

image.UnlockBits(bitmapData);

}

}





With the class completed we can move on to the inversion algorithm. This part is actually quite simple.



public new static void DoFilter(FastBitmap image)

{

image.LockPixels();

byte[] pixels = image.GetAllPixels();

for (int i = 0; i < pixels.Length; i++)

{

pixels[i] = (byte)(255 - pixels[i]);

}

image.SetAllPixels(pixels);

image.UnlockPixels();

}





Now we have an algorithm that in union with our FastBitmap class can invert a 320x240 image nearly instantly on a mobile device.



Thanks for reading. Let me know what you thought about this by leaving a comment!

[Author:Roshan Khan]

 http://blogs.msdn.com/windowsmobile/archive/2008/04/15/faster-c.aspx

上一页  [1] [2] 


  • 打印文档
  • 推荐好友
  • 返回顶部
  • 增大字体
  • 减少字体
关于本站 | 工作机会 | 合作网站 | 广告服务 | 市场合作| 联系我们 | 抽奖活动
版权所有: 武汉威俊科技有限公司 Copyright 2005-2007 www.ITCNW.COM All rights reserved