小编Gus*_*uma的帖子

在C++中使用C功能是不好的做法吗?

例如printf代替cout,scanf而不是cin使用#define宏,等?

c c++ language-features

18
推荐指数
5
解决办法
1652
查看次数

如何使用OnException方面(PostSharp)继续方法流?

我有以下代码:

[Serializable]
    class ExceptionAspectHandler:OnExceptionAspect
    {
        public override void OnException(MethodExecutionArgs args)
        {
            Console.WriteLine("{0}", args.Exception);
            args.FlowBehavior = FlowBehavior.Continue;
        }
    }

    [OnExceptionAspect]
    public static void divide()
            {
                int n = Convert.ToInt32(Console.ReadLine());
                var a = 100 / n; //the exception happens here
                Console.WriteLine("it should get here");
            }
Run Code Online (Sandbox Code Playgroud)

使用FlowBehavior.Continue结束divide()并返回main()方法.

c# aop exception-handling postsharp visual-studio

6
推荐指数
1
解决办法
2982
查看次数

用整数替换numpy数组中的RGB值非常慢

我想将numpy数组的rgb值替换为单个整数表示.我的代码有效,但速度太慢,我正在迭代每个元素.我可以加快速度吗?我是numpy的新手.

from skimage import io

# dictionary of color codes for my rgb values
_color_codes = {
    (255, 200, 100): 1,
    (223, 219, 212): 2,
    ...
}

# get the corresponding color code for the rgb vector supplied
def replace_rgb_val(rgb_v):
    rgb_triple = (rgb_v[0], rgb_v[1], rgb_v[2])
    if rgb_triple in _color_codes:
        return _color_codes[rgb_triple]
    else:
        return -1

# function to replace, this is where I iterate
def img_array_to_single_val(arr):
    return np.array([[replace_rgb_val(arr[i][j]) for j in range(arr.shape[1])] for i in range(arr.shape[0])])


# my images are square …
Run Code Online (Sandbox Code Playgroud)

python arrays rgb numpy image-processing

3
推荐指数
1
解决办法
4224
查看次数

二进制数字只有TextBox

我想验证TextBox的输入是二进制数.

我知道我可以用RegEx做到这一点,但我想要一个更"'中等'的验证,比如只允许输入1和0.

我想过使用MaskedTextBox,但我不知道如何只允许这两个字符.

.net c# winforms

2
推荐指数
1
解决办法
2594
查看次数

从int获取颜色

我正在显示灰度图像的直方图,我想用各自的颜色绘制每一行.例如:

for(int i=0;i<256;i++)
{
  Color c=getcolor(i);
  drawline(c,x,y,...);
}
Run Code Online (Sandbox Code Playgroud)

我想要像上面的getcolor函数.

c# colors image-processing

2
推荐指数
1
解决办法
1897
查看次数

Perl:用于数组定义的括号与括号,为什么一个被认为是标量?

我在Perl的HTML :: Template模块上学习教程.这是模板:

<!--template2.tmpl-->
<html>
<body>
<table>
  <tr>
    <th>Language</th>
    <th>Description</th>
  </tr>
  <tmpl_loop name="language">
  <tr>
    <td><tmpl_var name="language_name"></td>
    <td><tmpl_var name="description"></td>
  </tr>
  </tmpl_loop>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是CGI测试程序:

#!"C:\Strawberry\perl\bin\perl.exe" -wT
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
use HTML::Template;

my @rows = (
  {
    language_name => 'C#',
    description   => 'Created by Microsoft'
  },
  {
    language_name => 'PHP',
    description   => 'Hypertext Preprocessor'
  },
  {
    language_name => 'Haskell',
    description   => 'Functional language'
  },
);

print header;
my $template=HTML::Template->new(filename=>'template2.tmpl');
$template->param(language => @rows);
print $template->output();
Run Code Online (Sandbox Code Playgroud)

此操作失败,并显示以下错误: HTML::Template::param() …

arrays perl perl-html-template

1
推荐指数
1
解决办法
1270
查看次数