机器视觉入门之路(十九,图像旋转之后,c#)

总结一下,对c#的gdi显示做个对比,从c#图像旋转代码中截取(c++一并带过):

//旋转后放入picturebox2

8位显示旋转图像:......                                                 24位显示旋转图像:......

byte[] image1 = new byte[outwidth * outheight ];         byte[] image1 = new byte[outwidth * outheight *3];

......                                                                                       ......

  if (x >= 0 && x < 256 && y >= 0 && y < 256)               if (x >= 0 && x < 256 && y >= 0 && y < 256)
          {                                                                                    {
              int temp = j * outwidth + i;                                   int temp = j * outwidth + i;
              image1[temp ] = glob_buffer8[y * 256 + x];        image1[temp * 3] = glob_buffer8[y * 256 + x];
          }                                                                              image1[temp * 3+1] = glob_buffer8[y * 256 + x];

                                                                                          image1[temp * 3+2] = glob_buffer8[y * 256 + x];

                                                                                                  }     

Bitmap curbmp = new Bitmap(outwidth,                                     Bitmap curbmp = new Bitmap(outwidth,    

outheight,PixelFormat.Format8bppIndexed );                            outheight,PixelFormat. Format24bppRgb);

 System.Drawing.Imaging.ColorPalette cp = curbmp.Palette;
  for (int i = 0; i < 256; i++)
  {
      cp.Entries[i] = Color.FromArgb(255, i, i, i);
  }
  curbmp.Palette = cp;
BitmapData bmpdataout = curbmp.LockBits(                             ......

new Rectangl( (0, 0, outwidth, outheight),                                  ......

ImageLockMode.ReadWrite, curbmp.PixelFormat);                   ......
IntPtr ptr0 = bmpdataout.Scan0;//得到首地址                            ......

System.Runtime.InteropServices.Marshal.Copy              System.Runtime.InteropServices.Marshal.Copy

(image1, 0, ptr0, outwidth * outheight );                                      (image1, 0, ptr0, outwidth * outheight*3 ); 

curbmp.UnlockBits(bmpdataout);                                           ......
 pictureBox2.Image = curbmp;                                               ......

32位显示旋转图像

  ......

byte[] image1 = new byte[outwidth * outheight*4 ]; 

......

  if (x >= 0 && x < 256 && y >= 0 && y < 256)
          {
              int temp = j * outwidth + i;      
              image1[temp * 4] = glob_buffer8[y * 256 + x];
              image1[temp * 4 + 1] = glob_buffer8[y * 256 + x];
              image1[temp * 4+ 2] = glob_buffer8[y * 256 + x];
              image1[temp * 4 + 3] = 255;

          }

 Bitmap curbmp = new Bitmap(outwidth, outheight, PixelFormat.Format32bppArgb);

   BitmapData bmpdataout = curbmp.LockBits(new Rectangle(0, 0, outwidth, outheight), ImageLockMode.ReadWrite,
                                     curbmp.PixelFormat);
            IntPtr ptr0 = bmpdataout.Scan0;//得到首地址                
            System.Runtime.InteropServices.Marshal.Copy(image1, 0, ptr0, outwidth * outheight*4);
            curbmp.UnlockBits(bmpdataout);
            pictureBox2.Image = curbmp;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值