小编Nic*_*kon的帖子

byte []到BitmapImage转换失败

我有个问题.我想转换BitmapImagebyte[]数组并返回.

我写了这些方法:

public static byte[] ToByteArray(this BitmapImage bitmapImage)
{
    byte[] bytes;
    using (MemoryStream ms = new MemoryStream())
    {
        bitmapImage.BeginInit();
        bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
        bitmapImage.StreamSource.CopyTo(ms);
        bitmapImage.EndInit();
        bytes = ms.ToArray();
    }
    return bytes;
}

public static BitmapImage ToBitmapImage(this byte[] bytes, int width, int height)
{
    BitmapImage bitmapImage = new BitmapImage();
    using (MemoryStream ms = new MemoryStream(bytes))
    {
        ms.Position = 0;
        bitmapImage.BeginInit();
        bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
        bitmapImage.StreamSource = ms;
        bitmapImage.EndInit(); // HERE'S AN EXCEPTION!!!
    }
    return bitmapImage;
}
Run Code Online (Sandbox Code Playgroud)

第一个工作正常,但当我尝试转换byte[]成 …

c# wpf image bitmapimage

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

填充两个静态大小的div之间的空间

我有一个div元素(1200px宽度),包含3个内部divs.
第一个和最后一个具有静态大小(150px200px).我希望第二个在徽标和按钮之间居中.问题是我不知道如何集中这个div......

.container {
  width: 1200px;
  height: 100px;
  position: absolute;
  margin: 0 auto;
  background-color: grey;
}
.logo {
  width: 150px;
  height: 50px;
  float: left;
  background-color: darkred;
}
.text {
  width: auto;
  float: left;
}
.buttons {
  width: 200px;
  height: 70px;
  float: right;
  background-color: darkgreen;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
  <div class="logo"></div>
  <div class="text">SOME CENTERED TEXT HERE</div>
  <div class="buttons"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

html css

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

XmlWriter使得名称空间不正确

我有个问题.我编写了一个程序,将大量数据转换为VML-GML格式.问题是我需要使用XmlWriter...现在我的方法有问题如下:

private void StartDocument()
{
    _writer.WriteStartDocument();
    _writer.WriteStartElement("osgb", "FeatureCollection", "osgb");
    _writer.WriteAttributeString("osgb", "xmlns", "http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1");
    _writer.WriteAttributeString("gml", "xmlns", "http://www.opengis.net/gml");
    _writer.WriteAttributeString("xsi", "xmlns", "http://www.w3.org/2001/XMLSchema-instance");
    _writer.WriteAttributeString("schemaLocation", "xsi",
                                 "http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1 http://www.ordnancesurvey.co.uk/oswebsite/xml/cmdschema/local/V1.1/CMDFeatures.xsd");
    _writer.WriteAttributeString("fid", ""); // TODO: set fid here

    _writer.WriteStartElement("gml", "description", "gml");
    _writer.WriteValue("Ordnance Survey, (c) Crown Copyright. All rights reserved, 2011-03-02");
    _writer.WriteEndElement(); // description

    _writer.WriteElementString("osgb", "creationDate", "osgb", DateTime.Today.ToString("yyyy-MM-dd"));
}
Run Code Online (Sandbox Code Playgroud)

如何正确编写命名空间?我这样做了,输出是:

<?xml version="1.0" encoding="utf-8"?>
<osgb:FeatureCollection p1:osgb="http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1" 
p1:gml="http://www.opengis.net/gml"
p1:xsi="http://www.w3.org/2001/XMLSchema-instance" 
p2:schemaLocation="http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1 http://www.ordnancesurvey.co.uk/oswebsite/xml/cmdschema/local/V1.1/CMDFeatures.xsd"
fid="" xmlns:p2="xsi" xmlns:p1="xmlns" xmlns:osgb="osgb">
Run Code Online (Sandbox Code Playgroud)

这就是我需要的:

<osgb:FeatureCollection xmlns:osgb="http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1 http://www.ordnancesurvey.co.uk/oswebsite/xml/cmdschema/local/V1.1/CMDFeatures.xsd"
fid="">
Run Code Online (Sandbox Code Playgroud)

为什么会这样愚蠢的XmlWriter创造这样的事情一样p1, …

c# xml

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

TypeScript和继承

我需要一些帮助TypeScript.如何做扩展方法继承?

假设我们有一个MyClass只用一种方法命名的类Method1():

class MyClass {
   constructor () { }

   public Method1(): void {
   }
}
Run Code Online (Sandbox Code Playgroud)

现在我想创建一个子类,添加一个名为的新方法Method2():

class MyClassExtension {
   public Method2(): void {
   }
}
Run Code Online (Sandbox Code Playgroud)

当我有接口时,我可以通过声明一个具有相同名称的新接口来完成此操作:

interface MyInterface {
   Method1(): void;
}

interface MyInterface {
   Method2(): void;
}

var x: MyInterface;
x.Method1(); // ok
x.Method2(); // ok
Run Code Online (Sandbox Code Playgroud)

但我不知道如何为课程做这个:/任何人可以帮助我吗?

提前致谢!!!

typescript

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

重新格式化字符串

我想用来将Regex.Replace()(数字)(字母)等所有模式改为(数字)(空格)(字母).

例如
15A >>> 15 A
123KK >>> 123 KK

c# regex

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

将C#委托转换为TypeScript

你能告诉我怎么把它翻译成TypeScript?使用SharpKit.JavaScript;

namespace MyNamespace
{
    [JsType(JsMode.Prototype)]
    public class JsEventArgs
    {
    }

    public delegate void JsEventHandler<in T>(object sender, T args) where T : JsEventArgs;
    public delegate void JsEventHandler(object sender, JsEventArgs args);
}
Run Code Online (Sandbox Code Playgroud)

并在其他类中使用:

public event JsEventHandler<LayerVisivilityEventArgs> Changed;
Run Code Online (Sandbox Code Playgroud)

我试过了:

module JsEvent {

    export class JsEventArgs {
    }

    public JsEventHandler: (sender: Object, args: any) => void;
    public JsEventHandler: (sender: Object, args: JsEventArgs) => void;
}
Run Code Online (Sandbox Code Playgroud)

javascript c# typescript

0
推荐指数
2
解决办法
4835
查看次数

SQL中的奇怪语句

我找到了类似这样的地方:

SELECT [**] FROM [*]
Run Code Online (Sandbox Code Playgroud)

作为此页面所有者的人说" 你能算出这个吗? ".我尝试了这个语句MS SQL,OraclePostgreSQL得到语法不正确的错误.

有谁知道它是什么,它有什么作用?

sql

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

获取JS中用于过滤的对象数组的最大值

我有一组对象,如:

var myArr = [{
    number: 5,
    shouldBeCounted: true
}, {
    number: 6,
    shouldBeCounted: true
}, {
    number: 7,
    shouldBeCounted: false
}, ...];
Run Code Online (Sandbox Code Playgroud)

如何找到设置为?的number对象的最大值?我不想使用循环,只是想知道这是否可能(或类似的东西).shouldBeCountedtrueMath.max.apply

javascript arrays

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

标签 统计

c# ×4

javascript ×2

typescript ×2

arrays ×1

bitmapimage ×1

css ×1

html ×1

image ×1

regex ×1

sql ×1

wpf ×1

xml ×1