我正在尝试解决为Bitmap对象更改值ImageDescription的问题.添加文件的描述.搜索相关主题,我还没有找到解决方案.
我的代码:
public Bitmap ImageWithComment(Bitmap image)
{
string filePath = @"C:\1.jpg";
var data = Encoding.UTF8.GetBytes("my comment");
var propItem = image.PropertyItems.FirstOrDefault();
propItem.Type = 2;
propItem.Id = 40092;
propItem.Len = data.Length;
propItem.Value = data;
image.SetPropertyItem(propItem);
image.Save(filePath);
return image;
}
Run Code Online (Sandbox Code Playgroud)
但带有新评论的图片不保存在文件夹中((请帮帮我
我有一个方法,我想在同一个c#项目中的几乎所有类中使用.
public void Log(String line)
{
var file = System.IO.Path.GetPathRoot(Environment.SystemDirectory)+ "Logs.txt";
StreamWriter logfile = new StreamWriter(file, true);
// Write to the file:
logfile.WriteLine(DateTime.Now);
logfile.WriteLine(line);
logfile.WriteLine();
// Close the stream:
logfile.Close();
}
Run Code Online (Sandbox Code Playgroud)
在项目的其他类中重用此方法的方法是什么?
我正在尝试使用getRecords列表添加getRecords2列表.出于某些原因,在getRecords上,当我调用它时需要很长时间来处理和超时.
public static List<ListA> getRecords2(string id)
{
List<ListA> listOfRecords = new List<ListA>();
using (SqlConnection con = SqlConnect.GetDBConnection())
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "sp2";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@id", id));
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
ListA listMember = new ListA();
listMember.ID = (int)reader["ID"];
listMember.Name = reader["FullName"].ToString().Trim();
}
con.Close();
}
return listOfRecords;
}
public static List<ListA> getRecords(string id)
{
List<ListA> listOfRecords = new List<ListA>();
using (SqlConnection con = SqlConnect.GetDBConnection())
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = …Run Code Online (Sandbox Code Playgroud) 我是C#的新手.我正在编写一个程序,其中列表根据用户输入改变大小.列表是GPS坐标,所以它是
List<double[]> coordinates= new List<double[]>();
Run Code Online (Sandbox Code Playgroud)
但是我有一个需要double[][]格式的GPS坐标的函数,一个数组数组.看起来这很简单,因为它似乎是一个数组列表已经是一个数组数组.但是,我认为最合乎逻辑的事情就是失败:
double[][]test = new double[][]{};
test = coordinates.ToArray;
Run Code Online (Sandbox Code Playgroud)
使用"无法将方法组'ToArray'转换为非委托类型'double [] []'.您是否打算调用该方法?"
不确定这意味着什么或如何解决.任何建议表示赞赏.
我的学校项目需要帮助.我一直在努力,最终想出如何输出开始里程表和结束里程表=总里程驱动.对于总费用,我需要每天增加15美元的租金,加上每英里0.12美元.我该怎么做?这是我现在的代码:
//Step 1: Declaring variables to store our information.
decimal beginningOdometerDecimal;
decimal endingOdometerDecimal;
decimal rentedDecimal;
decimal totalSaleDecimal;
decimal averageSalesDecimal;
decimal carsReturned;
decimal totalMilesDecimal;
decimal finalCostDecimal;
//Step 2: Get the information from the user.
beginningOdometerDecimal = Decimal.Parse(txtBegin.Text);
endingOdometerDecimal = Decimal.Parse(txtEnd.Text);
rentedDecimal = Decimal.Parse(txtRent.Text);
//Step 3: Mathmatematical Calculations.
totalMilesDecimal = endingOdometerDecimal - beginningOdometerDecimal;
finalCostDecimal = totalMilesDecimal * (Decimal)0.12 + rentedDecimal + 15;
Run Code Online (Sandbox Code Playgroud)
如你所见,我使用finalCostDecimal等于totalmilesdecimal*$ 0.12 + rentedDecimal + 15.我不认为我使用了正确的代码.有人可以帮我吗?我被困住并尝试了很多.谢谢!
我是新手C#和使用者Windows Forms.
如截图所示,DataGridView当我点击取消按钮时,是否有人知道如何在一个选定行中水平交叉(制作十字线)?
我在网上搜索但我没有得到解决方案.
private void ButtonCancel_Click(object sender, EventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我理解第二个初始化打印一个"外部"和三个"内部".但是为什么第一个根本不打印,我希望它打印一个"外面".
DeferExecution a = new DeferExecution(); // prints nothing
DeferExecution b = new DeferExecution(null); // print one "outside" and three "inside".
class DeferExecution
{
public IEnumerable<string> Input;
public DeferExecution()
{
Input = GetIEnumerable();
}
public DeferExecution(string intput)
{
Input = GetIEnumerable().ToArray();
}
public IEnumerable<string> GetIEnumerable()
{
Console.WriteLine("outside");
var strings = new string[] {"a", "b", "c"};
foreach (var s in strings)
{
Console.WriteLine("inside");
yield return s;
}
}
}
Run Code Online (Sandbox Code Playgroud) 任何有关这方面的帮助将不胜感激.每当我运行我的程序时,我得到一个NullReferenceException未被用户代码处理.
因此,当我启动程序时,我会看到一个表单,我应该从名单列表中进行选择,并能够更新详细信息或删除它们,但下拉列表中没有任何内容.
我得到空引用:
comm.Parameters["@EmployeeID"].Value =
employeesList.SelectedItem.Value;
Run Code Online (Sandbox Code Playgroud)
这是CS文件中的选择按钮:
protected void selectButton_Click(object sender, EventArgs e)
{
// Declare objects
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
// Read the connection string from Web.config
string connectionString =
ConfigurationManager.ConnectionStrings[
"HelpDesk"].ConnectionString;
// Initialize connection
conn = new SqlConnection(connectionString);
// Create command
comm = new SqlCommand(
"SELECT FirstName, LastName, Username, Address, City, County, Post Code, " +
"HomePhone, Extension, MobilePhone FROM Employees " +
"WHERE EmployeeID = @EmployeeID", conn);
// Add command parameters
comm.Parameters.Add("@EmployeeID", System.Data.SqlDbType.Int);
comm.Parameters["@EmployeeID"].Value = …Run Code Online (Sandbox Code Playgroud) c# sql asp.net nullreferenceexception visual-web-developer-2010
我们有一个使用频繁的.Net 3.5应用程序,它读取"创建昂贵的数据"并对其进行缓存.但是,我们在读取缓存文件和写入缓存文件时遇到很多错误.我从StackOverflow论坛获得的一些建议是:
这是读取和写入文件的正确方法吗?请指教.
private XmlDocument ReadFromFile(string siteID, Type StuffType)
{
XmlDocument result = null;
var fsPath = FileSystemPath(siteID, StuffType.Name);
result = new XmlDocument();
using (var streamReader = new StreamReader(fsPath))
//using (var fileStream = new FileStream(fsPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
result.Load(streamReader);
}
//GC.Collect();
return result;
}
private readonly object thisObject = new object();
private void WriteToFile(string siteID, XmlDocument stuff, string fileName)
{
var fsPath = FileSystemPath(siteID, fileName);
lock (thisObject)
{
//using (var fileStream = new FileStream(fsPath, FileMode.Open, FileAccess.Read, …Run Code Online (Sandbox Code Playgroud) 我试图让WTF应用程序被用户点击"X"按钮来制作保存文件,现在这可以通过Message.Show完成或直接要求保存.我已经创建了一个代码但是当用户点击保存或取消时,错误窗口显示该程序开始工作并且它想要向Microsoft发送信息.
private void Window_Closing(object sender, CancelEventArgs e)
{
Microsoft.Win32.SaveFileDialog saveDlg = new Microsoft.Win32.SaveFileDialog();
saveDlg.DefaultExt = ".rtf";
saveDlg.Filter = "RTF Documents (.rtf)|*rtf";
Nullable<bool> rezultat = saveDlg.ShowDialog();
if (rezultat == true)
{
string filename = saveDlg.FileName;
System.IO.File.Create(filename);
}
{
this.Close();
}
}
Run Code Online (Sandbox Code Playgroud)