小编Iev*_*ida的帖子

C#已调整大小的图像具有黑色边框

我在.NET中的图像缩放有问题.我使用标准的Graphics类型来调整图像大小,如下例所示:

public static Image Scale(Image sourceImage, int destWidth, int destHeight)
{
        Bitmap toReturn = new Bitmap(sourceImage, destWidth, destHeight);

        toReturn.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution);

        using (Graphics graphics = Graphics.FromImage(toReturn))
        {
            graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.DrawImage(sourceImage, 0, 0, destWidth, destHeight);
        }
        return toReturn;
    }
Run Code Online (Sandbox Code Playgroud)

但是我对调整大小的图像有一个很大的问题:它们有灰色和黑色边框,制作没有图像的图像非常重要.

它们为什么出现以及我能做些什么使它们消失?

样本输出:

样本输出

.net c# scaling image

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

C#.解析并在字符串中找到一些单词

我有一些字符串

   bla bla bla bla  <I NEED THIS TEXT> 
Run Code Online (Sandbox Code Playgroud)

获取文本的最佳和最快的方法是<>什么?

.net c# string string-parsing

10
推荐指数
2
解决办法
6073
查看次数

多线程应用程序中没有锁的延迟加载

如果两个线程同时读取此属性会发生什么?

public static HugeType HugeType
{
    get
    {
        if (tenderCache == null)
        {
            tenderCache = Config.Get<HugeType>("HugeType", null);
        }
        return tenderCache;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的对象是只读的,如果创建了两个实例,则它并不重要.在任何情况下我都应该添加锁吗?

.net c# multithreading thread-safety

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

Silverlight树视图.无法绑定"IsExpanded"属性

我有TreeView控制权,我想将树节点的IsExpanded属性绑定到我的DataSource项目!

但我有一个例外:

System.Windows.Markup.XamlParseException occurred
  Message=Set property '' threw an exception.

  StackTrace:
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at SilverlightTree.BSTreeView.InitializeComponent()
       at SilverlightTree.BSTreeView..ctor()
  InnerException: System.NotSupportedException
       Message=Cannot set read-only property ''.
       StackTrace:
            at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value)
            at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue)
       InnerException: 
Run Code Online (Sandbox Code Playgroud)

内在异常:

{System.NotSupportedException: Cannot set read-only property ''.
Run Code Online (Sandbox Code Playgroud)

XAML:

<Grid x:Name="LayoutRoot">
    <controls:TreeView Name="treeView" SelectedItemChanged="treeView_SelectedItemChanged"
                       Style="{Binding  TreeViewConnectingLines}" BorderBrush="{x:Null}">
        <controls:TreeView.ItemTemplate>
            <toolkit:HierarchicalDataTemplate ItemsSource="{Binding Children}">
                <StackPanel Orientation="Horizontal"  Background="Transparent">
                    <toolkitDrag:ContextMenuService.ContextMenu>
                        <toolkitDrag:ContextMenu Loaded="ContextMenu_Loaded"
                                                 Opened="ContextMenu_Opened"/>
                    </toolkitDrag:ContextMenuService.ContextMenu>
                    <Image Source="{Binding Path=Type.Icon}" …
Run Code Online (Sandbox Code Playgroud)

data-binding silverlight wpf treeview

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

.Net从html页面中删除javascript和css代码块

我有html作为javascript和css代码块的字符串.

像这样的东西:

<script type="text/javascript">

  alert('hello world');

</script>

<style type="text/css">
  A:link {text-decoration: none}
  A:visited {text-decoration: none}
  A:active {text-decoration: none}
  A:hover {text-decoration: underline; color: red;}
</style>
Run Code Online (Sandbox Code Playgroud)

但我不需要它们.如何用reqular表达式删除那些块?

.net html c# regex

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

获取矩形和直线的交点

我需要得到矩形和直线的交点.在矩形(矩形的中心)内有B点,在外面有A点.我需要在一个矩形边框上找到C点.我也得到了矩形的宽度和高度.

在此输入图像描述

所有这些都将是WPF应用程序,所以如果任何构建功能我将非常高兴.

c# math wpf

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

IIS https 绑定有时会消失

我的开发机器上有 IIS,我托管默认的 asp.net 4.5 网站和 .NET 核心应用程序。

应用程序配置为仅通过 https 工作。有时,没有任何模式“https”会从配置列表中消失。在这种情况下,我手动添加它,但这真的很烦人。

任何可以一直删除此绑定的线索?

在此处输入图片说明

asp.net iis visual-studio iis-8

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

浏览器滚动条与silverlight应用程序的问题.(Html)

我有一个简单的silverlight应用程序,我需要为它添加Web浏览器滚动条.(滚动条不在我的silverlight应用程序中)

所以我有html:

<style type="text/css">
html, body {
    height: 100%;
    overflow: auto;
}
body {
    padding: 0;
    margin: 0;
}
#silverlightControlHost {
    height: 100%;
    min-height:600px;
    min-width:800px;
    text-align:center;
}
</style><body>
<form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost">
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">       
      <param name="source" value="ClientBin/Infopulse.MobileOptimizer.xap"/>          
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="minRuntimeVersion" value="4.0.50401.0" />
      <param name="autoUpgrade" value="true" />       
      <param name="culture" value="ru-ru" />
      <param name="uiculture" value="ru-ru" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>
    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form> …
Run Code Online (Sandbox Code Playgroud)

html css silverlight

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

如何在 asp.net 4.5 和 asp.net core 之间共享加密的 cookie?

我们很少有 ASP.NET 4.5 应用程序共享由 Web 配置机器密钥保护的身份验证 cookie (SSO) ,我不会更改它们。

ASP.NET 4.5 登录:

    var auth = FederatedAuthentication.SessionAuthenticationModule;
 auth.WriteSessionTokenToCookie(new System.IdentityModel.Tokens.SessionSecurityToken(cp));
Run Code Online (Sandbox Code Playgroud)

现在我们即将在同一个域中实现新的 ASP.NET 核心应用程序,我们希望保留旧的 cookie 授权机制。联合身份验证在 CORE 的运行时失败,是否有任何线索可以解密来自同一域的旧 cookie 并与 asp.net 和 asp.net core 共享新的 cookie?

ASP.NET 核心设置:

    public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
        {
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        services.AddMvc()
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizePage("/Contact");
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

        #region snippet1
        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie();
        #endregion

        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-authorization asp.net-core

6
推荐指数
0
解决办法
901
查看次数

使用 JavaScript 将 SVG 转换元素放入矩形边界

我正在努力解决一个问题,以将实际转换的 SVG 元素适合给定的矩形边界。

  • 给出目标矩形而不是转换。
  • 输入 rect 具有任何类型的转换。
  • 输入 rect 可以是任何转换组的子项。
  • 变换应该只应用于输入矩形。
  • 这个问题仅与 JavaScript 元素转换有关。

当元素本身只有转换时,这是一项简单的任务:

当父组未转换时

在这种情况下,目标和输入 getBoundingClientRect(屏幕坐标中的边界矩形)之间的比例等于适当的缩放因子。

但是当父元素也被转换时它不起作用:

   var inputElement = document.getElementById("input");
var destinationElement = document.getElementById("destination");


var inputBB = inputElement.getBoundingClientRect();
var outputBB = destinationElement.getBoundingClientRect();
var scaleX = outputBB.width / inputBB.width;
var scaleY = outputBB.height / inputBB.height;
// get offsets between figure center and destination rect center:
var offsetX = outputBB.x + outputBB.width / 2 - (inputBB.x + inputBB.width / 2);
var offsetY =
  outputBB.y + outputBB.height / 2 - (inputBB.y …
Run Code Online (Sandbox Code Playgroud)

javascript svg transformation matrix matrix-multiplication

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