小编Jam*_*uth的帖子

获取委托事件绑定的根元素 - jQuery

采用以下代码:

    // Bind the click event to the thumbnails.
    $("ul.hpList").on("click", "a.hpThumb", function (event) {

        event.preventDefault();

        var $this = $(this),

        // Surely there has to be a smarter way to do this.
            $hpList = $this.parents("ul.hpList");

        changeItem($this, $hpList);

    });
Run Code Online (Sandbox Code Playgroud)

如何更好地识别事件绑定的根祖先元素.我觉得搜索DOM很糟糕.

jquery

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

event.preventDefault()和多个事件

在我开始编写大量不起作用的代码之前,我想我会问这个问题.

event.preventDefault() 只取消click事件的默认动作不是吗?

从理论上讲,我应该能够将jQuery中的多个click事件处理程序绑定到给定目标,以执行不同的操作,如Ajax帖子和Google跟踪.

我错了吗?

javascript jquery events

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

异步HttpModule MVC

我有一个包含以下代码的同步HttpModule.

    /// <summary>
    /// Occurs as the first event in the HTTP pipeline chain of execution 
    /// when ASP.NET responds to a request.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">An <see cref="T:System.EventArgs">EventArgs</see> that 
    /// contains the event data.</param>
    private async void ContextBeginRequest(object sender, EventArgs e)
    {
        HttpContext context = ((HttpApplication)sender).Context;
        await this.ProcessImageAsync(context);
    }
Run Code Online (Sandbox Code Playgroud)

当我尝试从空的MVC4应用程序(NET 4.5)运行该模块时,我收到以下错误.

此时无法启动异步操作.异步操作只能在异步处理程序或模块中启动,或者在页面生命周期中的某些事件中启动.如果在执行页面时发生此异常,请确保将页面标记为<%@ Page Async ="true"%>.

我似乎错过了一些东西但是通过我的阅读,错误实际上不应该发生.

我有一个挖掘,但我似乎无法找到任何帮助,有没有人有任何想法?

asp.net-mvc httpmodule async-await

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

HttpModule中的异步EventHandler

你如何设置它们?

如果我在HttpModule中有以下代码.

public static event EventHandler<PostProcessingEventArgs> OnPostProcessing;
Run Code Online (Sandbox Code Playgroud)

并在使用的异步PostAuthorizeRequest任务中设置EventHandlerTaskAsyncHelper.

// Fire the post processing event.
EventHandler<PostProcessingEventArgs> handler = OnPostProcessing;
if (handler != null)
{
    handler(this, new PostProcessingEventArgs { CachedPath = cachedPath });
}
Run Code Online (Sandbox Code Playgroud)

然后使用它来点击它.

ProcessingModule.OnPostProcessing += this.WritePath;    

private async void WritePath(object sender, PostProcessingEventArgs e)
{
    await Task.Factory.StartNew(() => Debug.WriteLine(e.CachedPath));
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误.

在异步操作仍处于挂起状态时完成异步模块或处理程序.

编辑

好吧,所以在我看到所有这些答案之前,我得到它不通过提升事件处理程序抛出错误,如下所示.

EventHandlerTaskAsyncHelper postProcessHelper = 
new EventHandlerTaskAsyncHelper(this.PostProcessImage);

context.AddOnPostRequestHandlerExecuteAsync(postProcessHelper.BeginEventHandler,
postProcessHelper.EndEventHandler);

private Task PostProcessImage(object sender, EventArgs e)
{
    HttpContext context = ((HttpApplication)sender).Context;
    object cachedPathObject = context.Items[CachedPathKey];

    if (cachedPathObject != …
Run Code Online (Sandbox Code Playgroud)

c# events asynchronous httpmodule

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

正确实现2遍高斯模糊

我正在尝试利用高斯内核可分离的事实来实现高性能高斯模糊,即您可以将2D卷积表示为两个1D卷积的组合.

我能够使用以下代码生成两个我认为正确的内核.

/// <summary>
/// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function
/// </summary>
/// <param name="horizontal">Whether to calculate a horizontal kernel.</param>
/// <returns>The <see cref="T:float[,]"/></returns>
private float[,] CreateGaussianKernel(bool horizontal)
{
    int size = this.kernelSize;
    float[,] kernel = horizontal ? new float[1, size] : new float[size, 1];
    float sum = 0.0f;

    float midpoint = (size - 1) / 2f;
    for (int i = 0; i < size; i++)
    {
        float x = i - midpoint;
        float …
Run Code Online (Sandbox Code Playgroud)

c# image-processing gaussian convolution

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

防止在选择器内容之前包装内容:

我知道我可以只使用一个图像但是他们心智正常的人真的想要吗?

我正在尝试找到一种在无序列表中更改列表项前缀颜色的简洁方法.

使用:before选择器我可以很容易地做到这一点.(是的,我知道ie7,幸运的我没关系).

例如

.ul1 li
{
    list-style-type:none;
}

.ul1 li:before, .ol1 li:before
{
    content:"\25CF"; /*escaped unicode coloured circle*/
    color:#F68A39;
    font-weight:bold;
    font-size:18px;
    text-align:right;
    padding-right:6px;
    width:10px;
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是我的list-item中的:before内容现在将包含内容.有没有办法阻止这种情况?

这里有一些标记要开始......干杯!

<ul class="ul1">
    <li>
        Lorem Ipsum is simply dummy text of the printing and typesetting
        industry. Lorem Ipsum has been the industry's standard dummy text 
        ever since the 1500s, when an unknown printer took a galley of 
        type and scrambled it to make a type specimen book. It has …
Run Code Online (Sandbox Code Playgroud)

css

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

gdi+ 中的半色调效果

我将如何在 GDI+ 中模仿这种半色调效果?

它几乎看起来像是Floyd-Steinberg抖动版本的图像覆盖了一个完整的图像,但我不相信。

在此处输入图片说明

c# gdi+

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

在配置部分中创建动态键值对

我正在编写一个类来描述config部分,并且正在寻找一种可能的方法来满足以下情况:

<plugins>
    <add name="resize" maxheight="500px" maxwidth="500px"/>
    <add name="watermark" font="arial"/>
</plugins>
Run Code Online (Sandbox Code Playgroud)

列表中的每个项目可以包含不同的属性以及必需的name属性。设置默认部分非常简单,但是现在我被困在如何添加动态键/值对上。有任何想法吗?

    /// <summary>
    /// Represents a PluginElementCollection collection configuration element 
    /// within the configuration.
    /// </summary>
    public class PluginElementCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// Represents a PluginConfig configuration element within the 
        /// configuration.
        /// </summary>
        public class PluginElement : ConfigurationElement
        {
            /// <summary>
            /// Gets or sets the token of the plugin file.
            /// </summary>
            /// <value>The name of the plugin.</value>
            [ConfigurationProperty("name", DefaultValue = "", IsRequired = true)]
            public …
Run Code Online (Sandbox Code Playgroud)

c# asp.net configuration

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

在 C# 中旋转色调

我正在寻找复制这里找到的 CSS3 色调旋转行为

原图

原图

色调旋转 180 度的图像

色调旋转 180 度的图像

我已经可以准确地将 RGB 值转换为 HSL 值然后再转换回来,但我不确定应用于色调分量以复制输出的数学函数是什么。

c# gdi+

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

模仿这种成像效果

我问这个问题是因为另一个问题已经两年了并且没有准确回答。

我希望用 C#复制本文中提到的 PhotoShop 效果。Adobe 称它为彩色半色调,我认为它看起来像是某种旋转的 CMYK 半色调。无论哪种方式,我都不知道我会怎么做。

当前代码示例如下。

有任何想法吗?

彩色半色调效果

聚苯乙烯

这不是家庭作业。我希望升级我的 OSS 项目ImageProcessor 中的漫画书效果。

ImageProcessor 漫画效果

进度更新。

所以这里有一些代码来显示我到目前为止所做的......

我可以相当容易和准确地在 CMYK 和 RGB 之间进行转换,足以满足我的需要,并且还可以根据一系列点的每个颜色分量的强度打印出一系列有图案的椭圆。

我刚才遇到的是旋转每种颜色的图形对象,以便将点放置在代码中指定的角度。任何人都可以给我一些关于如何去做的指示吗?

public Image ProcessImage(ImageFactory factory)
{
    Bitmap newImage = null;
    Image image = factory.Image;

    try
    {
        int width = image.Width;
        int height = image.Height;

        // These need to be used.
        float cyanAngle = 105f;
        float magentaAngle = 75f;
        float yellowAngle = 90f;
        float keylineAngle = 15f;

        newImage = new Bitmap(width, height);
        newImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

        using …
Run Code Online (Sandbox Code Playgroud)

c# graphics imageprocessor

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