当前位置: 首页>>代码示例>>C#>>正文


C# NPPImage_8uC1.CopyToDevice方法代码示例

本文整理汇总了C#中ManagedCuda.NPP.NPPImage_8uC1.CopyToDevice方法的典型用法代码示例。如果您正苦于以下问题:C# NPPImage_8uC1.CopyToDevice方法的具体用法?C# NPPImage_8uC1.CopyToDevice怎么用?C# NPPImage_8uC1.CopyToDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ManagedCuda.NPP.NPPImage_8uC1的用法示例。


在下文中一共展示了NPPImage_8uC1.CopyToDevice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btn_open_Click

        private void btn_open_Click(object sender, EventArgs e)
        {
            if (!_nppOK) return;

            CleanUp();

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Images|*.jpg;*.bmp;*.png;*.tif";
            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

            Bitmap src = new Bitmap(ofd.FileName);

            switch (src.PixelFormat)
            {
                case PixelFormat.Format24bppRgb:
                    _colorChannels = 3;
                    break;
                case PixelFormat.Format32bppArgb:
                    _colorChannels = 4;
                    break;
                case PixelFormat.Format32bppRgb:
                    _colorChannels = 4;
                    break;
                case PixelFormat.Format8bppIndexed:
                    _colorChannels = 1;
                    break;
                default:
                    _colorChannels = 0;
                    txt_info.AppendText(ofd.FileName + " has an unsupported pixel format.\n");
                    break;
            }

            try
            {
                switch (_colorChannels)
                {
                    case 1:
                        //Allocate memory on device for one channel images...
                        src_c1 = new NPPImage_8uC1(src.Width, src.Height);
                        dest_c1 = new NPPImage_8uC1(src.Width, src.Height);
                        src_c1.CopyToDevice(src);
                        txt_info.AppendText("Info: Loaded image '" + ofd.FileName + "' succesfully (Size: " + src.Width.ToString() + " x " + src.Height.ToString() + ", color channels: " + _colorChannels.ToString() + ")\n");
                        break;
                    case 3:
                        //As of version 5, NPP has new histogram and LUT functions for three channel images, no more need to convert first to 4 channels.
                        //Allocate memory on device for four channel images...
                        src_c3 = new NPPImage_8uC3(src.Width, src.Height);
                        dest_c3 = new NPPImage_8uC3(src.Width, src.Height);

                        //Fill 3 channel image in device memory
                        src_c3.CopyToDevice(src);

                        txt_info.AppendText("Info: Loaded image '" + ofd.FileName + "' succesfully (Size: " + src.Width.ToString() + " x " + src.Height.ToString() + ", color channels: " + _colorChannels.ToString() + ")\n");
                        break;
                    case 4:
                        //Allocate memory on device for four channel images...
                        src_c4 = new NPPImage_8uC4(src.Width, src.Height);
                        dest_c4 = new NPPImage_8uC4(src.Width, src.Height);
                        src_c4.CopyToDevice(src);
                        txt_info.AppendText("Info: Loaded image '" + ofd.FileName + "' succesfully (Size: " + src.Width.ToString() + " x " + src.Height.ToString() + ", color channels: " + _colorChannels.ToString() + ")\n");
                        break;
                }
            }
            catch (Exception ex)
            {
                if (ex is NPPException)
                {
                    txt_info.AppendText("NPPException: " + ex.Message + "\n");
                    CleanUp();
                }
                else if (ex is CudaException)
                {
                    txt_info.AppendText("CudaException: " + ex.Message + "\n");
                    CleanUp();
                }
                else throw;
            }
            //Show original image
            pictureBox_src.Image = src;
        }
开发者ID:kunzmi,项目名称:managedCuda,代码行数:80,代码来源:Form1.cs


注:本文中的ManagedCuda.NPP.NPPImage_8uC1.CopyToDevice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。