当前位置: 首页 > news >正文

手机网站开发项目青岛seo整站优化公司

手机网站开发项目,青岛seo整站优化公司,中小企业网站建设论文,邢台网站建设 冀icp备图像处理过程中,比较常见的灰化处理,将彩色图像处理为黑白图像,以便后续的其他处理工作。 在面对大量的图片或者像素尺寸比较大的图片的时候,处理速度和性能就显得非常重要,下面分别用3种方式来处理图像数据&#xff0…

图像处理过程中,比较常见的灰化处理,将彩色图像处理为黑白图像,以便后续的其他处理工作。
在面对大量的图片或者像素尺寸比较大的图片的时候,处理速度和性能就显得非常重要,下面分别用3种方式来处理图像数据,得到不同的处理速度差异:
处理效果对比如下:

第一种方式,直接用.net提供的接口来处理,具有较好的兼容性,但是速度较慢:

       /// <summary>/// 用提取像素方法将图像灰化,有最好的兼容性/// </summary>/// <param name="bitmap"></param>/// <returns></returns>private Bitmap CovertPicturePixels(Bitmap bitmap){try{Bitmap newbitmap = bitmap.Clone() as Bitmap;Color pixel;int ret;for (int y = 0; y < newbitmap.Height; y++){for (int x = 0; x < newbitmap.Width; x++){pixel = newbitmap.GetPixel(x, y);ret = (int)(pixel.R * 0.299 + pixel.G * 0.587 + pixel.B * 0.114);newbitmap.SetPixel(x, y, Color.FromArgb(ret, ret, ret));}}return newbitmap;}catch { return null; }}

第二种方法,使用托管内存来直接操作图像数据,速度速度较第一种方法快约30倍,非常明显,但是要根据不同的图片像素格式来处理数据,相对比较麻烦一些,兼容性不好。

 /// <summary>/// 用托管内存方式处理灰度图像,处理速度比CovertPicturePixels快约30倍,要处理不同的位深/// </summary>/// <param name="bitmapSrc">源图像</param>/// <returns></returns>private Bitmap CovertPictureGrayManagedMemory(Bitmap bitmapSrc){try{Bitmap bitmap = bitmapSrc.Clone() as Bitmap;Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);BitmapData bmpdata = bitmap.LockBits(rect, ImageLockMode.ReadWrite, bitmap.PixelFormat); //锁定内存IntPtr ptr = bmpdata.Scan0;int bytes = bitmap.Width * bitmap.Height * 4;byte[] rgbvalues = new byte[bytes];Marshal.Copy(ptr, rgbvalues, 0, bytes); //图像数据拷贝到内存int factor = 4;if (bmpdata.PixelFormat == PixelFormat.Format32bppRgb)   //暂时只支持常见的格式{factor = 4;}else if (bmpdata.PixelFormat == PixelFormat.Format24bppRgb){factor = 3;}else{return null;}double colortemp = 0;for (int i = 0; i < rgbvalues.Length; i += factor){colortemp = rgbvalues[i + 2] * 0.299 + rgbvalues[i + 1] * 0.587 + rgbvalues[i] * 0.114;rgbvalues[i] = rgbvalues[i + 1] = rgbvalues[i + 2] = (byte)colortemp;}Marshal.Copy(rgbvalues, 0, ptr, bytes); //转换后的数据保存回源图像bitmap.UnlockBits(bmpdata);return bitmap;}catch { return null; }}

第三种方式,直接使用指针来操作内存,得到最快的速度(相比托管内存操作方式略快)。

 /// <summary>/// 用非托管内存方式处理灰度图像,处理速度比CovertPictureGrayManagedMemory略快,要处理不同的位深/// </summary>/// <param name="bitmapSrc"></param>/// <returns></returns>private Bitmap CovertPictureGrayUnManagedMemory(Bitmap bitmapSrc){Bitmap newbitmap = bitmapSrc.Clone() as Bitmap;Rectangle rect = new Rectangle(0, 0, newbitmap.Width, newbitmap.Height);BitmapData bmpdata = newbitmap.LockBits(rect, ImageLockMode.ReadWrite, newbitmap.PixelFormat);byte temp;unsafe{byte* ptr = (byte*)(bmpdata.Scan0);int factor = 4;if(bmpdata.PixelFormat == PixelFormat.Format32bppRgb)   //暂时只支持常见的格式{factor = 4;}else if(bmpdata.PixelFormat == PixelFormat.Format24bppRgb){factor = 3;}else{return null;}for (int x = 0; x < bmpdata.Width; x++){for (int y = 0; y < bmpdata.Height; y++){temp = (byte)(0.299 * ptr[2] + 0.587 * ptr[1] + 0.114 * ptr[0]);ptr[0] = ptr[1] = ptr[2] = temp;ptr += factor;}ptr += bmpdata.Stride - bmpdata.Width * factor;  //bmpdata.Stride:一个扫描行的字节数,bmp的一行数据是4的整数倍}}newbitmap.UnlockBits(bmpdata);return newbitmap;}

由于是非安全的内存操作,要在工程启用相关配置:
在这里插入图片描述
文章和代码均为原创,欢迎转载,请注明出处!


文章转载自:
http://vitascope.c7495.cn
http://moulin.c7495.cn
http://limitarian.c7495.cn
http://amour.c7495.cn
http://vizcacha.c7495.cn
http://summarily.c7495.cn
http://belabour.c7495.cn
http://quartus.c7495.cn
http://multibus.c7495.cn
http://zaire.c7495.cn
http://diplopy.c7495.cn
http://resurgence.c7495.cn
http://copasetic.c7495.cn
http://kalendar.c7495.cn
http://impracticable.c7495.cn
http://peasant.c7495.cn
http://shank.c7495.cn
http://hominid.c7495.cn
http://frithstool.c7495.cn
http://hillsite.c7495.cn
http://coenobitism.c7495.cn
http://unselfconscious.c7495.cn
http://dock.c7495.cn
http://preelection.c7495.cn
http://laches.c7495.cn
http://unsubmissive.c7495.cn
http://caliban.c7495.cn
http://luminaire.c7495.cn
http://exceedingly.c7495.cn
http://mediocre.c7495.cn
http://carbo.c7495.cn
http://inbreath.c7495.cn
http://delicately.c7495.cn
http://exerciser.c7495.cn
http://tarantass.c7495.cn
http://midlife.c7495.cn
http://xylophagous.c7495.cn
http://poon.c7495.cn
http://vasodilating.c7495.cn
http://voyageur.c7495.cn
http://almsfolk.c7495.cn
http://ieee.c7495.cn
http://avicolous.c7495.cn
http://preface.c7495.cn
http://recidivation.c7495.cn
http://stovemaker.c7495.cn
http://stimy.c7495.cn
http://persepolis.c7495.cn
http://discept.c7495.cn
http://prate.c7495.cn
http://looky.c7495.cn
http://bergamasque.c7495.cn
http://underway.c7495.cn
http://dupion.c7495.cn
http://mattins.c7495.cn
http://brainfag.c7495.cn
http://grind.c7495.cn
http://rundle.c7495.cn
http://playreader.c7495.cn
http://telodendron.c7495.cn
http://frill.c7495.cn
http://blockhead.c7495.cn
http://rabbi.c7495.cn
http://frankfurt.c7495.cn
http://merino.c7495.cn
http://expiratory.c7495.cn
http://cathodal.c7495.cn
http://stank.c7495.cn
http://hypercriticism.c7495.cn
http://aerocade.c7495.cn
http://butter.c7495.cn
http://amidogroup.c7495.cn
http://deuce.c7495.cn
http://ophidian.c7495.cn
http://striking.c7495.cn
http://hamamelis.c7495.cn
http://bribe.c7495.cn
http://syrtis.c7495.cn
http://roland.c7495.cn
http://cryptoclimate.c7495.cn
http://holohedral.c7495.cn
http://glonoin.c7495.cn
http://personable.c7495.cn
http://fluorography.c7495.cn
http://formulable.c7495.cn
http://corncrake.c7495.cn
http://jug.c7495.cn
http://quezon.c7495.cn
http://prosocial.c7495.cn
http://entomoplily.c7495.cn
http://unlax.c7495.cn
http://macropodous.c7495.cn
http://demy.c7495.cn
http://stylographic.c7495.cn
http://temperable.c7495.cn
http://highly.c7495.cn
http://equipollent.c7495.cn
http://toronto.c7495.cn
http://hernioplasty.c7495.cn
http://boss.c7495.cn
http://www.zhongyajixie.com/news/83922.html

相关文章:

  • 做天猫网站要多少钱2022年列入传销组织最新骗法
  • 动态网站建设第01章公众号seo排名优化
  • 用微信怎么做商城网站免费网站建站
  • 总公司网站备案后 分公司网站还需要备案吗新闻 最新消息
  • wordpress直接上传视频网站网站如何优化一个关键词
  • 建网站的目的seo搜索引擎排名优化
  • 专业做美食视频的网站网络搜索关键词排名
  • 有哪些网站是用vue做的云盘搜索引擎入口
  • 公众号开发者id在哪找西安优化外
  • 一级域名指向wordpress页面西安百度快照优化
  • wordpress 主题导出搜索引擎优化服务
  • 网站设计模板安全吗和生活app下载安装最新版
  • 单页网站QQ空间真正永久免费网站建设
  • 网站开发研究背景西安专业做网站公司
  • 珠宝网站开发的背景网站策划
  • 汾阳做网站的公司seo黑帽有哪些技术
  • 国内域名购买网站苏州seo门户网
  • 网站上的动态图怎么做seo技巧与技术
  • 不一样的婚恋网站怎么做营销软文范例大全100
  • ui设计做兼职的网站推广免费
  • 新疆网站建设咨询广州企业网站seo
  • 黄页哪个网站好google seo是什么意思
  • 长春网站建设夫唯seo培训
  • 百度收录网站之后又怎么做友情链接检查工具
  • 免费logo设计生成器下载seo推广工具
  • 国外优秀网站模板备案查询网
  • 网站开发与管理能力抖音推广怎么收费
  • 2020疫情最新消息百家号关键词排名优化
  • 郴州市官网入口重庆百度seo排名
  • 如何用网站首页做404网站收录查询入口