| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c# >> C# tu xiang chu li zhi - gei ni de tu pian da shang LOGO

C# tu xiang chu li zhi - gei ni de tu pian da shang LOGO

2008-12-13 08:23:56 编辑來源:互联网 评论
 
 
 
本文为【C#图像处理之-给你的图片打上LOGO】的拼音翻译版
  zuo tu pian chu li ruan jian , ken ding hui yu dao zhe yang de xu qiu : ru he ba yi zhang tu pian fang zai ling yi zhang tu pian shang , bi ru zai da tu pian zhong da shang gong si huo ge ren de Logo deng deng 。
  qi shi yuan li hen jian dan 。 jia she wo men you yi zhang 800 * 600 de da tu pian (Bitmap b0), xiang zai (10,10) de wei zhi shang da shang Logo(Bitmap b1),Logo tu pian da xiao shi 150 * 30。 hen jian dan , wo men yi da tu pian de (10,10) wei zhi zuo wei qi shi wei zhi , zuo yi ge 150 * 30 de ju xing , ba Logo tu pian zheng ge ti huan zhe ge ju xing 。
  lao gui ju , huan shi yong BitmapData lai bang zhu wo men shi xian zhe ge gong neng 。view plaincopy to clipboardprint?
  // qu yi da tu (X,Y) wei qi dian ,w * h de ju xing qu yu
  BitmapData srcData = b0.LockBits(new Rectangle(X,Y,w,h),ImageLockMode.WriteOnly,PixelFormat.Format24bppRgb);
  // qu zheng ge Logo
  BitmapData dstData = b1.LockBits(new Rectangle(0,0,w,h),ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
  unsafe
  {
  byte* pIn = (byte*)srcData.Scan0.ToPointer();
  byte* pLogo = (byte*)dstData.Scan0.ToPointer();
  for (int y = 0; y < h; y++)
  {
  for (int x = 0; x < w; x++)
  {
  // fu zhi Logo tu de xiang su
  pIn[0] = (byte)pLogo[0];
  pIn[1] = (byte)pLogo[1];
  pIn[2] = (byte)pLogo[2];
  pIn += 3;
  pLogo += 3;
  }
  pIn += srcData.Stride - w * 3;
  pLogo += dstData.Stride - w * 3;
  }
  b0.UnlockBits(srcData);
  b1.UnlockBits(dstData);
  }
  // qu yi da tu (X,Y) wei qi dian ,w * h de ju xing qu yu
  BitmapData srcData = b0.LockBits(new Rectangle(X,Y,w,h),ImageLockMode.WriteOnly,PixelFormat.Format24bppRgb);
  // qu zheng ge Logo
  BitmapData dstData = b1.LockBits(new Rectangle(0,0,w,h),ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
  unsafe
  {
  byte* pIn = (byte*)srcData.Scan0.ToPointer();
  byte* pLogo = (byte*)dstData.Scan0.ToPointer();
  for (int y = 0; y < h; y++)
  {
  for (int x = 0; x < w; x++)
  {
  // fu zhi Logo tu de xiang su
  pIn[0] = (byte)pLogo[0];
  pIn[1] = (byte)pLogo[1];
  pIn[2] = (byte)pLogo[2];
  pIn += 3;
  pLogo += 3;
  }
  pIn += srcData.Stride - w * 3;
  pLogo += dstData.Stride - w * 3;
  }
  b0.UnlockBits(srcData);
  b1.UnlockBits(dstData);
  } zhe yang , wei tu pian da Logo de gong neng jiu shi xian le 。 dang ran , huan ke yi you bie de fang fa , bi ru yong BitBlt zhe ge API han shu , huo zhe shi yong GDI+ de DrawImage han shu 。
  dan zhe yang you ge xiao wen ti ,Logo qu yu yong yuan shi ge ju xing 。 jia ru wo de Logo shi ge yuan xing , zhi xi wang zai da tu shang chu xian yuan xing de Logo er bu shi zheng kuai ju xing , na you gai ru he shi xian ne ?
  zhe ge wen ti qi shi ke yi zhe yang li jie : wo men rang Logo de bei jing bian tou ming 。 er suo wei tou ming , jiu shi liang zhang tu pian die jia shi , shang ceng tu pian “ tou ming ” qu yu zhong de xiang su , reng ran shi yong xia ceng tu de xiang ying xiang su lai dai ti 。 dan zai RGB mo shi xia , bing mei you “ tou ming ” zhe ge gai nian ( wo men de tao lun dou zai yong PixelFormat.Format24bppRgb,PixelFormat.Format32bppArgb zhong de Alpha fen liang zhi chi “ tou ming du ”), yin ci wo men xu yao zi ji gui ding yi zhong yan se , fan shi zhe ge yan se de , dou zuo wei “ tou ming ” chu li 。
  bi ru , wo men de Logo shi hei di de , na me jiu zhi ding hei se zuo wei tou ming se 。
  xiu gai suan fa ye hen jian dan , fan shi yu dao Logo tu zhong xiang su yan se shi hei se ( dang ran zhe shi ge shen shu , ke yi zi ji gai ) de , jiu yong da tu xiang ying wei zhi de yan se lai dai ti , fou ze huan shi shi yong Logo de xiang su se 。 xia mian shi suan fa :view plaincopy to clipboardprint?
  // yin wei you ke neng yao hui xie , suo yi yuan tu de ImageLockMode zhe ci shi ReadWrite
  BitmapData srcData = b0.LockBits(new Rectangle(X, Y, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
  BitmapData dstData = b1.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
  unsafe
  {
  byte* pIn = (byte*)srcData.Scan0.ToPointer();
  byte* pLogo = (byte*)dstData.Scan0.ToPointer();
  for (int y = 0; y < h; y++)
  {
  for (int x = 0; x < w; x++)
  {
  // pan duan dang qian dian shi fou tou ming se
  // qu de dang qian se
  Color c = Color.FromArgb(pLogo[2], pLogo[1], pLogo[0]);
  if (!ColorIsSimilar(c, TransColor, delta))
  {
  // bu shi tou ming se ,b0 dang qian wei zhi de yan se yong b1 dui ying wei zhi de lai dai ti
  pIn[0] = (byte)pLogo[0];
  pIn[1] = (byte)pLogo[1];
  pIn[2] = (byte)pLogo[2];
  }
  pIn += 3;
  pLogo += 3;
  }
  pIn += srcData.Stride - w * 3;
  pLogo += dstData.Stride - w * 3;
  }
  b0.UnlockBits(srcData);
  b1.UnlockBits(dstData);
  }
  // yin wei you ke neng yao hui xie , suo yi yuan tu de ImageLockMode zhe ci shi ReadWrite
  BitmapData srcData = b0.LockBits(new Rectangle(X, Y, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
  BitmapData dstData = b1.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
  unsafe
  {
  byte* pIn = (byte*)srcData.Scan0.ToPointer();
  byte* pLogo = (byte*)dstData.Scan0.ToPointer();
  for (int y = 0; y < h; y++)
  {
  for (int x = 0; x < w; x++)
  {
  // pan duan dang qian dian shi fou tou ming se
  // qu de dang qian se
  Color c = Color.FromArgb(pLogo[2], pLogo[1], pLogo[0]);
  if (!ColorIsSimilar(c, TransColor, delta))
  {
  // bu shi tou ming se ,b0 dang qian wei zhi de yan se yong b1 dui ying wei zhi de lai dai ti
  pIn[0] = (byte)pLogo[0];
  pIn[1] = (byte)pLogo[1];
  pIn[2] = (byte)pLogo[2];
  }
  pIn += 3;
  pLogo += 3;
  }
  pIn += srcData.Stride - w * 3;
  pLogo += dstData.Stride - w * 3;
  }
  b0.UnlockBits(srcData);
  b1.UnlockBits(dstData);
  } wo men zai shang mian de suan fa zhong chu xian le ling yi ge xiao suan fa , pan duan yan se C0,C1 shi fou xiang deng 。 dang ran ru guo liang ge yan se de RGB fen liang dou xiang deng na jiu ken ding shi xiang deng le , dan kao lv dao rong cha fang mian de yin su , wo men xu yao yi ge geng ling huo de suan fa 。
  wo men zhi dao , yi ge yan se you RGB san ge fen liang zu cheng , mei ge fen liang qu zhi [0,255] de zheng shu 。 zhe yang , ren yi yi ge yan se dou shi zhe ge you xian kong jian zhong de yi ge dian 。 liang ge yan se de “ xiang si du ” shi fou zai fa zhi fan wei nei de wen ti , zui jian dan de si lu ye jiu ke yi ren wei qiu zheng kong jian liang dian de ju li shi fou zai fa zhi fan wei nei 。
  kong jian liang dian ju li gong shi :r2 = (x0-x1)2 + (y0-y1)2 + (z0-z1)2
  xia mian shi wo de suan fa 。view plaincopy to clipboardprint?
  /// <summary>
  /// yan se shi fou jin si
  /// </summary>
  /// <param name="c0"> yan se 0</param>
  /// <param name="c1"> yan se 1</param>
  /// <param name="delta"> rong cha </param>
  /// <returns> shi / fou </returns>
  public static bool ColorIsSimilar(Color c0, Color c1, int delta)
  {
  int r0, r1, g0, g1, b0, b1;
  r0 = c0.R;
  r1 = c1.R;
  g0 = c0.G;
  g1 = c1.G;
  b0 = c0.B;
  b1 = c1.B;
  if ((r0-r1)*(r0-r1) + (g0-g1) * (g0-g1) + (b0-b1) * (b0-b1) <= delta * delta)
  {
  return true;
  }
  else
  {
  return false;
  }
  }
  /// <summary>
  /// yan se shi fou jin si
  /// </summary>
  /// <param name="c0"> yan se 0</param>
  /// <param name="c1"> yan se 1</param>
  /// <param name="delta"> rong cha </param>
  /// <returns> shi / fou </returns>
  public static bool ColorIsSimilar(Color c0, Color c1, int delta)
  {
  int r0, r1, g0, g1, b0, b1;
  r0 = c0.R;
  r1 = c1.R;
  g0 = c0.G;
  g1 = c1.G;
  b0 = c0.B;
  b1 = c1.B;
  if ((r0-r1)*(r0-r1) + (g0-g1) * (g0-g1) + (b0-b1) * (b0-b1) <= delta * delta)
  {
  return true;
  }
  else
  {
  return false;
  }
  } zui hou zai lai kan kan yi zhong qing kuang 。 wo men xu yao Logo ban tou ming de cheng xian , mao si shui yin yang de xiao guo 。 you le shang mian liang zhong chu li tu pian de jing yan , bu nan ren shi dao , da tu b0 de zhi ding qu yu zhong xu yao hun he yuan shi xiang su he Logo tu pian b1 xiang su hou de xin xiang su tian chong 。
  bu nan xiang xiang , xin xiang su zhi ying gai jie he le da tu he Logo tu liang fang mian yin su de 。Logo tu yue tou ming , da tu shou de ying xiang yue xiao 。 suo yi zhe li wo men ke yi cai yong jia quan ping yun de fang fa lai de dao hun he hou de xin zhi 。
  xin zhi = (1 - bu tou ming du %)* da tu xiang su zhi + bu tou ming du % * Logo tu xiang su zhi
  wan zheng de han shu ru xia :view plaincopy to clipboardprint?
  /// <summary>
  /// he bing liang zhang tu pian , zhi chi bu tou ming du he tou ming se
  /// </summary>
  /// <param name="b0"> tu pian yi </param>
  /// <param name="b1"> tu pian er </param>
  /// <param name="X"> qi shi zuo biao X</param>
  /// <param name="Y"> qi shi zuo biao Y</param>
  /// <param name="b1_alpha"> tu pian er de bu tou ming du </param>
  /// <param name="TransColor"> bei zuo wei tou ming se chu li de yan se </param>
  /// <param name="delta"> tou ming se de rong cha </param>
  /// <returns> he bing hou de tu pian </returns>
  public static Bitmap KiMerge(Bitmap b0, Bitmap b1, int X, int Y, int b1_alpha,Color TransColor,int delta)
  {
  if (b0.Equals(null) || b1.Equals(null))
  {
  return null;
  }
  int w0 = b0.Width;
  int h0 = b0.Height;
  int w1 = b1.Width;
  int h1 = b1.Height;
  int w, h;
  if (X + w1 > w0)
  {
  w = w0 - X;
  }
  else
  {
  w = w1;
  }
  if (Y + h1 > h0)
  {
  h = h0 - Y;
  }
  else
  {
  h = h1;
  }
  BitmapData srcData = b0.LockBits(new Rectangle(X, Y, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
  BitmapData dstData = b1.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
  unsafe
  {
  byte* pIn = (byte*)srcData.Scan0.ToPointer();
  byte* pLogo = (byte*)dstData.Scan0.ToPointer();
  for (int y = 0; y < h; y++)
  {
  for (int x = 0; x < w; x++)
  {
  // pan duan tou ming se
  Color c = Color.FromArgb(pLogo[2], pLogo[1], pLogo[0]);
  if (!ColorIsSimilar(c, TransColor, delta))
  {
  float bili = (float)b1_alpha / (float)255; // bu shi tou ming se , jia quan ping yun
  float inbili = 1.0f - bili;
  int r, g, b;
  b = (int)(pIn[0] * inbili + pLogo[0] * bili);
  g = (int)(pIn[1] * inbili + pLogo[1] * bili);
  r = (int)(pIn[2] * inbili + pLogo[2] * bili);
  pIn[0] = (byte)b;
  pIn[1] = (byte)g;
  pIn[2] = (byte)r;
  }
  pIn += 3;
  pLogo += 3;
  }
  pIn += srcData.Stride - w * 3;
  pLogo += dstData.Stride - w * 3;
  }
  b0.UnlockBits(srcData);
  b1.UnlockBits(dstData);
  }
  return b0;
  }
  /// <summary>
  /// he bing liang zhang tu pian , zhi chi bu tou ming du he tou ming se
  /// </summary>
  /// <param name="b0"> tu pian yi </param>
  /// <param name="b1"> tu pian er </param>
  /// <param name="X"> qi shi zuo biao X</param>
  /// <param name="Y"> qi shi zuo biao Y</param>
  /// <param name="b1_alpha"> tu pian er de bu tou ming du </param>
  /// <param name="TransColor"> bei zuo wei tou ming se chu li de yan se </param>
  /// <param name="delta"> tou ming se de rong cha </param>
  /// <returns> he bing hou de tu pian </returns>
  public static Bitmap KiMerge(Bitmap b0, Bitmap b1, int X, int Y, int b1_alpha,Color TransColor,int delta)
  {
  if (b0.Equals(null) || b1.Equals(null))
  {
  return null;
  }
  int w0 = b0.Width;
  int h0 = b0.Height;
  int w1 = b1.Width;
  int h1 = b1.Height;
  int w, h;
  if (X + w1 > w0)
  {
  w = w0 - X;
  }
  else
  {
  w = w1;
  }
  if (Y + h1 > h0)
  {
  h = h0 - Y;
  }
  else
  {
  h = h1;
  }
  BitmapData srcData = b0.LockBits(new Rectangle(X, Y, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
  BitmapData dstData = b1.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
  unsafe
  {
  byte* pIn = (byte*)srcData.Scan0.ToPointer();
  byte* pLogo = (byte*)dstData.Scan0.ToPointer();
  for (int y = 0; y < h; y++)
  {
  for (int x = 0; x < w; x++)
  {
  // pan duan tou ming se
  Color c = Color.FromArgb(pLogo[2], pLogo[1], pLogo[0]);
  if (!ColorIsSimilar(c, TransColor, delta))
  {
  float bili = (float)b1_alpha / (float)255; // bu shi tou ming se , jia quan ping yun
  float inbili = 1.0f - bili;
  int r, g, b;
  b = (int)(pIn[0] * inbili + pLogo[0] * bili);
  g = (int)(pIn[1] * inbili + pLogo[1] * bili);
  r = (int)(pIn[2] * inbili + pLogo[2] * bili);
  pIn[0] = (byte)b;
  pIn[1] = (byte)g;
  pIn[2] = (byte)r;
  }
  pIn += 3;
  pLogo += 3;
  }
  pIn += srcData.Stride - w * 3;
  pLogo += dstData.Stride - w * 3;
  }
  b0.UnlockBits(srcData);
  b1.UnlockBits(dstData);
  }
  return b0;
  } dang ran fang fa you hen duo , zhe li zhi shi cong yuan li de jiao du chan shu le yi xia wo de guan dian , shui you geng hao de fang fa qing rang wo zhi dao 。【原文】【汉音对照
 
 
 
 
 
 
 
 59.*.*.* 发表于2012-02-01 21:00:19
  中国微软.NET技术交流社区
  cnntec.com
  回复
  
  
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
zuo tu pian chu li ruan jian , ken ding hui yu dao zhe yang de xu qiu : ru he ba yi zhang tu pian fang zai ling yi zhang tu pian shang , bi ru zai da tu pian zhong da shang gong si huo ge ren de Logo deng deng 。 qi shi yuan li hen jian dan 。 jia she wo men you yi zhang 800 * 600 de da tu pian (Bitmap b0), xiang zai (10,10) de wei zhi shang da shang Logo(Bitmap b1),Logo tu pian da xiao shi 150 * 30。 hen jian dan , wo men yi da tu pian de (10,10) wei zhi zuo wei qi shi wei zhi , zuo yi ge 150 * 30 de ju xing , ba Logo tu pian zheng ge ti huan zhe ge ju xing 。 lao gui ju , huan shi yong BitmapData lai bang zhu wo men shi xian zhe ge gong neng 。view plaincopy to clipboardprint? // qu yi da tu (X,Y) wei qi dian ,w * h de ju xing qu yu BitmapData srcData = b0.LockBits(new Rectangle(X,Y,w,h),ImageLockMode.WriteOnly,PixelFormat.Format24bppRgb); // qu zheng ge Logo BitmapData dstData = b1.LockBits(new Rectangle(0,0,w,h),ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pLogo = (byte*)dstData.Scan0.ToPointer(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { // fu zhi Logo tu de xiang su pIn[0] = (byte)pLogo[0]; pIn[1] = (byte)pLogo[1]; pIn[2] = (byte)pLogo[2]; pIn += 3; pLogo += 3; } pIn += srcData.Stride - w * 3; pLogo += dstData.Stride - w * 3; } b0.UnlockBits(srcData); b1.UnlockBits(dstData); } // qu yi da tu (X,Y) wei qi dian ,w * h de ju xing qu yu BitmapData srcData = b0.LockBits(new Rectangle(X,Y,w,h),ImageLockMode.WriteOnly,PixelFormat.Format24bppRgb); // qu zheng ge Logo BitmapData dstData = b1.LockBits(new Rectangle(0,0,w,h),ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pLogo = (byte*)dstData.Scan0.ToPointer(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { // fu zhi Logo tu de xiang su pIn[0] = (byte)pLogo[0]; pIn[1] = (byte)pLogo[1]; pIn[2] = (byte)pLogo[2]; pIn += 3; pLogo += 3; } pIn += srcData.Stride - w * 3; pLogo += dstData.Stride - w * 3; } b0.UnlockBits(srcData); b1.UnlockBits(dstData); } zhe yang , wei tu pian da Logo de gong neng jiu shi xian le 。 dang ran , huan ke yi you bie de fang fa , bi ru yong BitBlt zhe ge API han shu , huo zhe shi yong GDI+ de DrawImage han shu 。 dan zhe yang you ge xiao wen ti ,Logo qu yu yong yuan shi ge ju xing 。 jia ru wo de Logo shi ge yuan xing , zhi xi wang zai da tu shang chu xian yuan xing de Logo er bu shi zheng kuai ju xing , na you gai ru he shi xian ne ? zhe ge wen ti qi shi ke yi zhe yang li jie : wo men rang Logo de bei jing bian tou ming 。 er suo wei tou ming , jiu shi liang zhang tu pian die jia shi , shang ceng tu pian “ tou ming ” qu yu zhong de xiang su , reng ran shi yong xia ceng tu de xiang ying xiang su lai dai ti 。 dan zai RGB mo shi xia , bing mei you “ tou ming ” zhe ge gai nian ( wo men de tao lun dou zai yong PixelFormat.Format24bppRgb,PixelFormat.Format32bppArgb zhong de Alpha fen liang zhi chi “ tou ming du ”), yin ci wo men xu yao zi ji gui ding yi zhong yan se , fan shi zhe ge yan se de , dou zuo wei “ tou ming ” chu li 。 bi ru , wo men de Logo shi hei di de , na me jiu zhi ding hei se zuo wei tou ming se 。 xiu gai suan fa ye hen jian dan , fan shi yu dao Logo tu zhong xiang su yan se shi hei se ( dang ran zhe shi ge shen shu , ke yi zi ji gai ) de , jiu yong da tu xiang ying wei zhi de yan se lai dai ti , fou ze huan shi shi yong Logo de xiang su se 。 xia mian shi suan fa :view plaincopy to clipboardprint? // yin wei you ke neng yao hui xie , suo yi yuan tu de ImageLockMode zhe ci shi ReadWrite BitmapData srcData = b0.LockBits(new Rectangle(X, Y, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); BitmapData dstData = b1.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pLogo = (byte*)dstData.Scan0.ToPointer(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { // pan duan dang qian dian shi fou tou ming se // qu de dang qian se Color c = Color.FromArgb(pLogo[2], pLogo[1], pLogo[0]); if (!ColorIsSimilar(c, TransColor, delta)) { // bu shi tou ming se ,b0 dang qian wei zhi de yan se yong b1 dui ying wei zhi de lai dai ti pIn[0] = (byte)pLogo[0]; pIn[1] = (byte)pLogo[1]; pIn[2] = (byte)pLogo[2]; } pIn += 3; pLogo += 3; } pIn += srcData.Stride - w * 3; pLogo += dstData.Stride - w * 3; } b0.UnlockBits(srcData); b1.UnlockBits(dstData); } // yin wei you ke neng yao hui xie , suo yi yuan tu de ImageLockMode zhe ci shi ReadWrite BitmapData srcData = b0.LockBits(new Rectangle(X, Y, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); BitmapData dstData = b1.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pLogo = (byte*)dstData.Scan0.ToPointer(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { // pan duan dang qian dian shi fou tou ming se // qu de dang qian se Color c = Color.FromArgb(pLogo[2], pLogo[1], pLogo[0]); if (!ColorIsSimilar(c, TransColor, delta)) { // bu shi tou ming se ,b0 dang qian wei zhi de yan se yong b1 dui ying wei zhi de lai dai ti pIn[0] = (byte)pLogo[0]; pIn[1] = (byte)pLogo[1]; pIn[2] = (byte)pLogo[2]; } pIn += 3; pLogo += 3; } pIn += srcData.Stride - w * 3; pLogo += dstData.Stride - w * 3; } b0.UnlockBits(srcData); b1.UnlockBits(dstData); } wo men zai shang mian de suan fa zhong chu xian le ling yi ge xiao suan fa , pan duan yan se C0,C1 shi fou xiang deng 。 dang ran ru guo liang ge yan se de RGB fen liang dou xiang deng na jiu ken ding shi xiang deng le , dan kao lv dao rong cha fang mian de yin su , wo men xu yao yi ge geng ling huo de suan fa 。 wo men zhi dao , yi ge yan se you RGB san ge fen liang zu cheng , mei ge fen liang qu zhi [0,255] de zheng shu 。 zhe yang , ren yi yi ge yan se dou shi zhe ge you xian kong jian zhong de yi ge dian 。 liang ge yan se de “ xiang si du ” shi fou zai fa zhi fan wei nei de wen ti , zui jian dan de si lu ye jiu ke yi ren wei qiu zheng kong jian liang dian de ju li shi fou zai fa zhi fan wei nei 。 kong jian liang dian ju li gong shi :r2 = (x0-x1)2 + (y0-y1)2 + (z0-z1)2 xia mian shi wo de suan fa 。view plaincopy to clipboardprint? /// <summary> /// yan se shi fou jin si /// </summary> /// <param name="c0"> yan se 0</param> /// <param name="c1"> yan se 1</param> /// <param name="delta"> rong cha </param> /// <returns> shi / fou </returns> public static bool ColorIsSimilar(Color c0, Color c1, int delta) { int r0, r1, g0, g1, b0, b1; r0 = c0.R; r1 = c1.R; g0 = c0.G; g1 = c1.G; b0 = c0.B; b1 = c1.B; if ((r0-r1)*(r0-r1) + (g0-g1) * (g0-g1) + (b0-b1) * (b0-b1) <= delta * delta) { return true; } else { return false; } } /// <summary> /// yan se shi fou jin si /// </summary> /// <param name="c0"> yan se 0</param> /// <param name="c1"> yan se 1</param> /// <param name="delta"> rong cha </param> /// <returns> shi / fou </returns> public static bool ColorIsSimilar(Color c0, Color c1, int delta) { int r0, r1, g0, g1, b0, b1; r0 = c0.R; r1 = c1.R; g0 = c0.G; g1 = c1.G; b0 = c0.B; b1 = c1.B; if ((r0-r1)*(r0-r1) + (g0-g1) * (g0-g1) + (b0-b1) * (b0-b1) <= delta * delta) { return true; } else { return false; } } zui hou zai lai kan kan yi zhong qing kuang 。 wo men xu yao Logo ban tou ming de cheng xian , mao si shui yin yang de xiao guo 。 you le shang mian liang zhong chu li tu pian de jing yan , bu nan ren shi dao , da tu b0 de zhi ding qu yu zhong xu yao hun he yuan shi xiang su he Logo tu pian b1 xiang su hou de xin xiang su tian chong 。 bu nan xiang xiang , xin xiang su zhi ying gai jie he le da tu he Logo tu liang fang mian yin su de 。Logo tu yue tou ming , da tu shou de ying xiang yue xiao 。 suo yi zhe li wo men ke yi cai yong jia quan ping yun de fang fa lai de dao hun he hou de xin zhi 。 xin zhi = (1 - bu tou ming du %)* da tu xiang su zhi + bu tou ming du % * Logo tu xiang su zhi wan zheng de han shu ru xia :view plaincopy to clipboardprint? /// <summary> /// he bing liang zhang tu pian , zhi chi bu tou ming du he tou ming se /// </summary> /// <param name="b0"> tu pian yi </param> /// <param name="b1"> tu pian er </param> /// <param name="X"> qi shi zuo biao X</param> /// <param name="Y"> qi shi zuo biao Y</param> /// <param name="b1_alpha"> tu pian er de bu tou ming du </param> /// <param name="TransColor"> bei zuo wei tou ming se chu li de yan se </param> /// <param name="delta"> tou ming se de rong cha </param> /// <returns> he bing hou de tu pian </returns> public static Bitmap KiMerge(Bitmap b0, Bitmap b1, int X, int Y, int b1_alpha,Color TransColor,int delta) { if (b0.Equals(null) || b1.Equals(null)) { return null; } int w0 = b0.Width; int h0 = b0.Height; int w1 = b1.Width; int h1 = b1.Height; int w, h; if (X + w1 > w0) { w = w0 - X; } else { w = w1; } if (Y + h1 > h0) { h = h0 - Y; } else { h = h1; } BitmapData srcData = b0.LockBits(new Rectangle(X, Y, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); BitmapData dstData = b1.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pLogo = (byte*)dstData.Scan0.ToPointer(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { // pan duan tou ming se Color c = Color.FromArgb(pLogo[2], pLogo[1], pLogo[0]); if (!ColorIsSimilar(c, TransColor, delta)) { float bili = (float)b1_alpha / (float)255; // bu shi tou ming se , jia quan ping yun float inbili = 1.0f - bili; int r, g, b; b = (int)(pIn[0] * inbili + pLogo[0] * bili); g = (int)(pIn[1] * inbili + pLogo[1] * bili); r = (int)(pIn[2] * inbili + pLogo[2] * bili); pIn[0] = (byte)b; pIn[1] = (byte)g; pIn[2] = (byte)r; } pIn += 3; pLogo += 3; } pIn += srcData.Stride - w * 3; pLogo += dstData.Stride - w * 3; } b0.UnlockBits(srcData); b1.UnlockBits(dstData); } return b0; } /// <summary> /// he bing liang zhang tu pian , zhi chi bu tou ming du he tou ming se /// </summary> /// <param name="b0"> tu pian yi </param> /// <param name="b1"> tu pian er </param> /// <param name="X"> qi shi zuo biao X</param> /// <param name="Y"> qi shi zuo biao Y</param> /// <param name="b1_alpha"> tu pian er de bu tou ming du </param> /// <param name="TransColor"> bei zuo wei tou ming se chu li de yan se </param> /// <param name="delta"> tou ming se de rong cha </param> /// <returns> he bing hou de tu pian </returns> public static Bitmap KiMerge(Bitmap b0, Bitmap b1, int X, int Y, int b1_alpha,Color TransColor,int delta) { if (b0.Equals(null) || b1.Equals(null)) { return null; } int w0 = b0.Width; int h0 = b0.Height; int w1 = b1.Width; int h1 = b1.Height; int w, h; if (X + w1 > w0) { w = w0 - X; } else { w = w1; } if (Y + h1 > h0) { h = h0 - Y; } else { h = h1; } BitmapData srcData = b0.LockBits(new Rectangle(X, Y, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); BitmapData dstData = b1.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pLogo = (byte*)dstData.Scan0.ToPointer(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { // pan duan tou ming se Color c = Color.FromArgb(pLogo[2], pLogo[1], pLogo[0]); if (!ColorIsSimilar(c, TransColor, delta)) { float bili = (float)b1_alpha / (float)255; // bu shi tou ming se , jia quan ping yun float inbili = 1.0f - bili; int r, g, b; b = (int)(pIn[0] * inbili + pLogo[0] * bili); g = (int)(pIn[1] * inbili + pLogo[1] * bili); r = (int)(pIn[2] * inbili + pLogo[2] * bili); pIn[0] = (byte)b; pIn[1] = (byte)g; pIn[2] = (byte)r; } pIn += 3; pLogo += 3; } pIn += srcData.Stride - w * 3; pLogo += dstData.Stride - w * 3; } b0.UnlockBits(srcData); b1.UnlockBits(dstData); } return b0; } dang ran fang fa you hen duo , zhe li zhi shi cong yuan li de jiao du chan shu le yi xia wo de guan dian , shui you geng hao de fang fa qing rang wo zhi dao 。
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
华丽的模特拍摄(8)
华丽的模特拍摄(7)
华丽的模特拍摄(6)
华丽的模特拍摄(5)
八里沟
朝阳宫
天下峨眉 云上金顶
老家(四)
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有