Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
A similar question has already been asked on this thread:
Save JPG in progressive format
However, the answer marked is basically saying that it can't be done. However, considering it is done using other software, it definitely is something which C# can do.
Is there any way this can be done?
Magick.NET can do it with a code like this
using (MagickImage image = new MagickImage("input.png"))
{
// Set the format and write to a stream so ImageMagick won't detect the file type.
image.Format = MagickFormat.Pjpeg;
using (FileStream fs = new FileStream("output.jpg", FileMode.Create))
{
image.Write(fs);
}
// Write to .jpg file
image.Write("PJEG:output.jpg");
// Or to a .pjpeg file
image.Write("output.pjpg");
}
You can find more details here.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 51 mins ago.
Improve this question
Microsoft Modelbuilder's autogenerated code suggests to load training/inference data like this:
var imageBytes = File.ReadAllBytes(path);
When I create a 100x100 bit solid colored cube in MSpaint and save it as .png and use above function to load the file I get a byte[342], while I would expect 100x100x3 bytes if it were uncompressed(?).
Am I correct to assume that the compression is intact here?
If a model is trained with compressed data, does it need similary compressed data when making predictions?
Could a model's performance improve if trained on uncompressed data?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there an identical hex_md5 algorithm in C# to this: http://pajhome.org.uk/crypt/md5/md5.html
I've looked at the RFC 1321, but I wasn't sure if this was a custom implementation based on RFC 1321. I need it to be identical i.e. the value that hex_md5 would return in the JavaScript implementation will be the same in the C# implementation (if one exists).
This is a fairly typical implementation that should match the library's:
string dataToHash = "aaa";
byte[] dataToHashBytes = System.Text.Encoding.ASCII.GetBytes(dataToHash);
using (var md5 = MD5.Create())
{
var hashed = md5.ComputeHash(dataToHashBytes);
Console.WriteLine(BitConverter.ToString(hashed).Replace("-", ""));
}
The C# code produces 47BCE5C74F589F4867DBD57E9CA9F808. This is fairly trivial code, it takes a string, "aaa", converts it to a a byte representation using the ASCII encoding, then hashes it. Finally, we covert it to hexadecimal.
And here is a JSFiddle from the library producing the same thing: http://jsfiddle.net/QC57K/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have 2 file paths:
absolute:
/Content/assets2/otherfolder/another/this/
relative:
../../../../assets/img/logo.gif
when I do Path.Combine(absolute, relative) I get:
/Content/assets2/otherfolder/another/this/../../../../assets/img/logo.gif
which works fine, but what I want to get:
/Content/assets/img/logo.gif
I need a Regex or code that removes the "../" with the corresponding folder:
/Content/assets2/otherfolder/another/this/../../../../assets/img/logo.gif
/Content/assets2/otherfolder/another/../../../assets/img/logo.gif
/Content/assets2/otherfolder/../../assets/img/logo.gif
/Content/assets2/../assets/img/logo.gif
finally into:
/Content/assets/img/logo.gif
You don't need a Regex for that. Actually, I think it would be impossible to define in a reliable way in Regex. Instead, use Path.GetFullPath:
string combined = Path.Combine(path1, path2);
string prettyPath = Path.GetFullPath(combined);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I Write the text file Demo.txt with Html tags i have save it as html(every time when i write it again)
this is my code...
System.IO.File.WriteAllText(#"D:\Demo.txt", string.Empty);
StreamWriter file2 = new StreamWriter(#"D:\Demo.txt", true);
int j = 0;
file2.WriteLine("<html><table border='1'>");
file2.WriteLine("<tr bgcolor='#99CCFF' >");
file2.WriteLine("</html>");
how to save it as .htm alredy having extention .txt...how to refresh text file or save it with .htm
Conditionally copy the file before or after you write to it.
if(System.IO.File.Exists("d:\Demo.txt"))
System.IO.File.Copy("d:\Demo.txt", "d:\Demo.htm", true);
http://msdn.microsoft.com/en-us/library/system.io.file.copy.aspx
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I have a folder C:\MergeMe\ that is full of tab-delimited text files, but the number of files is unknown at any given time.
How do I read and store the names of the text files in the MergeMe directory into an array?
Use System.IO.Directory.GetFiles(). If you know the extension, you can, for example call:
Directory.GetFiles(#"C:\MergeMe\*.txt")
If you need other options, there are overloads that allow you to provide them.
static void Main(string[] args)
{
foreach (string file in Directory.GetFiles("MyPath"))
{
if (Path.GetExtension(file)=="youExtension")
{
using (StreamReader sr = new StreamReader(file))
{
//Your code
}
}
}
}