以流格式保存图片框中的图像

我想保存一个装在图片框中的图片流。当我保存为png格式时它工作正常但是当我想要以其他格式保存它我得到 GDI +exception中发生了一般错误 我的代码: Image Img = pictureBox1.Image; byte[] inputImage = new byte[Img.Width * Img.Height]; System.IO.MemoryStream ms = new System.IO.MemoryStream(); ms.Read(inputImage, 0, Img.Width * Img.Height); if (System.Drawing.Imaging.ImageFormat.Jpeg.Equals(Img.RawFormat)) { pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); } else if (System.Drawing.Imaging.ImageFormat.Gif.Equals(Img.RawFormat)) { ms.Seek(0, SeekOrigin.Begin); pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); } else if (System.Drawing.Imaging.ImageFormat.Png.Equals(Img.RawFormat)) { pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); } else if (System.Drawing.Imaging.ImageFormat.Bmp.Equals(Img.RawFormat)) { pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); }

通过HttpRequest登录Windows Live ID

我希望通过HttpRequest / HttpResponse与一个网站进行交互。 但是网络需要通过Windows Live ID登录。 我转到实时登录页面,但我无法从登录页面获得任何可用的响应。 用于访问登录页面的代码: var request = (HttpWebRequest)WebRequest.Create(“http://login.live.com/”); request.Timeout = 30000; request.UserAgent = “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)”; request.Accept = “text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”; request.Headers.Add(“Accept-Language”, “en-us,en;q=0.5”); request.Headers.Add(“Accept-Charset”, “ISO-8859-1,utf-8;q=0.7,*;q=0.7”); request.Headers.Add(“Keep-Alive”, “300”); request.ContentType = “application/x-www-form-urlencoded”; request.CookieContainer = new CookieContainer(); request.Method = WebRequestMethods.Http.Get; var response = (HttpWebResponse)request.GetResponse(); 并回应: 必须允许Cookie […]

找不到我的Entity Framework数据库

我对代码第一entity framework数据库有点困惑。 我创建了一个新的DbContext和类,我将在该上下文中存储,如下所示: namespace MyProject.Subproject.Something { public class MyItem { public string One { get; set; } public string Two { get; set; } [Key] public string Three { get; set; } public string Four { get; set; } } public class MyAppData : DbContext { public DbSet MyItems { get; set; } } } […]

entity framework7身份种子

我们在EF7中使用Code First,我想添加一个具有Identity Seed的列,该另一个值为1。 目前,我们可以在迁移过程中通过EntityTypeBuilder将其设置为自动增量: entityBuilder.Property(e => e.PropertyName).ValueGeneratedOnAdd(); 但是我无法找到如何更改身份种子。 它是否仍然需要像其他版本的EF一样更新? 例如,编写一些自定义的SQL并在迁移期间运行它? 如何在entity framework代码中首先为几个表生成标识种子值 如何使用SQL Compact 4首先使用Entity Framework 4代码在ID列上设置Identity种子? 在EF7中,似乎没有SqlServerMigrationSqlGenerator > override Generate(AltherTableOperation alterTableOperation)代码SqlServerMigrationSqlGenerator > override Generate(AltherTableOperation alterTableOperation) ?

System.ComponentModel.Win32Exception:拒绝访问…错误

我想在我们的网站上打开一个文档文件。 为此,我写下面的代码。 try { Process proc = new Process(); proc.StartInfo = new ProcessStartInfo(Server.MapPath(“~/Quatation/PREMIUMQUOTATION1.doc”)); proc.Start(); } catch (WebException we) { } 它在本地运行非常好但在Web服务器上的web它给我一个错误 System.ComponentModel.Win32Exception:访问被拒绝? 请建议,我该怎么办?

使用WPF自定义控件库(.NET Framework)中的普通WPF项目中的App.xaml

我有一个带有App.xaml (不是资源字典)的WPF项目,其中包含一些材料设计和ViewModelLocator(MVVM),如下所示: <!– –> 当我在WPFProject中创建一个Window时,它工作得很好。 但我也有一个WPF Custome Library项目。 如何从我的自定义WPF项目中的WPFProject访问App.xaml。 这是Custom WPF Library项目中的Window.xaml: 定位器和MaterialDesign的内容无法解析。 有任何想法吗? 或者这甚至可能吗?

如何使用LINQ,C#向元素添加属性?

我有一个XElement对象,它有许多属性,我只想在元素中添加另一个属性。 我该怎么做呢?

get set for simple variables的好处是什么

可能重复: 公共字段与自动属性 我想这会在某个地方得到解答,但我不会在通常的地方找到它。 我在想,这样做有什么好处 private int _foo; public int foo {get {return _foo;} set{_foo = value;}} 要么 public int foo {get; set;} 只是 public int foo; 如果需要更复杂的操作,我可以看到好处,但这样的简单案例的好处是什么?

使用MahApps保持样式在WPF中扩展TextBox

我创建了一个自定义文本框类,用于validation用户的输入以仅允许hex值,并在xaml中使用此新文本框(HexTextBox)。 它运行良好,但HexTextBox丢失了Mahapps的所有样式,包括配色方案和TextBoxHelper。 你知道如何使用这个扩展的TexBox并保持风格吗? HexTextBox: public class HexTextBox : TextBox { public HexTextBox() { } /// /// Raise when a keyboard key is pressed. /// /// The event args. protected override void OnPreviewKeyDown(KeyEventArgs e) { if (e.Key == Key.Space) { e.Handled = true; } base.OnPreviewKeyDown(e); } /// /// Raise when a text will be inputed in […]

在C#中获取iCloud联系人列表

在搜索了iCloud API之后,我在NodeJS和Python上找到了一些例子,但不幸的是,我对它们并不熟悉。 我想知道如何在C#上获取iCloud联系人列表。 关于python的示例: https : //github.com/mindcollapse/iCloud-API/blob/master/iCloud.py NodeJS上的示例: https ://www.snip2code.com/Snippet/65033/Request-Contact-List-From -iCloud 我尝试将登录代码解析为C#: private void iCloudLogin() { string guiid = Guid.NewGuid().ToString(“N”); //string url = “https://p12-setup.icloud.com/setup/ws/1/login?clientBuildNumber=1P24&clientId=” + guiid; string url = “https://setup.icloud.com/setup/ws/1/login?clientBuildNumber=1P24&clientId=” + guiid; using (var client = new WebClient()) { client.Headers.Set(“Origin”, “https://www.icloud.com”); client.Headers.Set(“Referer”, “https://www.icloud.com”); client.Headers.Set(“User-Agent”, “Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36”); […]