Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I am trying to write a c# code to extract each frame of a .avi file and save it into a provided directory. Do you know any suitable library to use for such purpose?
Note: The final release must work on all systems regardless of installed codec, or system architecture. It must not require the presence of another program (like MATLAB) on the machine.
Thanks in advance.
Tunc
This is not possible, unless you add some restrictions to your input avi files or have control over encoder used to create them. To get an image you will have to decode it first, and for that you will need an appropriate codec installed or deployed with your app. And i doubt its possible to account for every codec out there or install/deploy them all. So no, you won't be able to open just any avi file. You can, however, support the most popular (or common in your context) codecs.
The easiest way to do it is indeed using an FFMPEG, since its alredy includes some of the most common codecs (if you dont mind extra 30+Mb added to your app). As for wrappers, i used AForge wrapper in the past and really liked it, because of how simple it is to work with. Here is an example from its docs:
// create instance of video reader
VideoFileReader reader = new VideoFileReader( );
// open video file
reader.Open( "test.avi" );
// read 100 video frames out of it
for ( int i = 0; i < 100; i++ )
{
Bitmap videoFrame = reader.ReadVideoFrame( );
videoFrame.Save(i + ".bmp")
// dispose the frame when it is no longer required
videoFrame.Dispose( );
}
reader.Close( );
There is also a VfW (which is included in Windows by default) wrapper in AForge, if you want to keep it simple without involving external libraries. You will still need VfW compatible codecs installed tho (some of them are included in Windows by default, most are not).
You could have a look at FFmpeg: http://www.ffmpeg.org/
Some C# related info: Using FFmpeg in .net?
or: http://www.ffmpeg-csharp.com/
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 3 years ago.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am working on file and folder upload system and i want to add some security to it.
i have followed this Article , The security point number 6 on it says:
6. Keep tight control of permissions
Any uploaded file will be owned by the web server. But it only needs
read/write permission, not execute permissions. After the file is
downloaded, you could apply additional restrictions if this is
appropriate. Sometimes it can be helpful to remove the execute
permission from directories to prevent the server from enumerating
files.
How to apply that using C#
If I'm understanding you correctly, you want to upload a file to a remote server and then change the file to read only. Here is one option. Start by getting a File Object. After that you can set the access control then supply the access you want to provide.
It might be something like this:
using System.IO;
using System.Security.AccessControl;
private void SetFileAccess(string path)
{
var fileSecurity = new FileSecurity();
var readRule = new FileSystemAccessRule("identityOfUser", FileSystemRights.ReadData, AccessControlType.Allow);
var writeRule = new FileSystemAccessRule("identityOfUser", FileSystemRights.WriteData, AccessControlType.Allow);
var noExecRule = new FileSystemAccessRule("identityOfUser", FileSystemRights.ExecuteFile, AccessControlType.Deny);
fileSecurity.AddAccessRule(readRule);
fileSecurity.AddAccessRule(writeRule);
fileSecurity.AddAccessRule(noExecRule);
File.SetAccessControl(path, fileSecurity);
}
MSDN Link to File
MSDN Link to SetAccessControl Method
MSDN Link to File System Rights
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I've got this task that requires me to generate some basic C code using a software written in C#.
The generated code should be based on some input files I provide to my software, we'll call it btOS for easy of communication.
So when starting btOS I give it as input file1, config.xml. When I hit run it should output a file.c that contains some basic structures and/or methods based on what the input files contain.
Is there any elegant way to do this ? Maybe some already generated templates or methods or stuff like that ? The only way I could think of handling this was creating specific strings in C# and outputting them to a C file.
L.E.: It seems that somehow my question was not clear enough. I assume the fault of including C++ in the title, I have remove it but I don't see how that is relevant because the question was very simple.
Anyway, to make it more clear. All i need to do is read some config files (their content is irrelevant, all they contain are some variables that will be used to generate some function templates, which will mostly impact the name of the function) - and write an output file with the extension .C (as in Main.c) that will contain those templates I generated.
So, again, the question: Are there any "elegant" and maybe somehow "professional" ways to do this other than using custom generated strings within the code that I will write to the file ? Right now the only way I see fit to do this without too much hassle is using some template text files with a naming convention defined by me(e.g. function_variableName{...}) where I just change the [variableName] text with whatever I need to to be there and "Abracadabra" I have a function that I will write to the file.
Now as Soonts suggested please try and be helpful, read multiple times if you don't clearly understand or maybe even don't bother - let somebody who is interested in this topic, tries to help or gain some new knowledge before flagging it.
Double Cheers.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
What I mean is, could one possibly make a program that does the equivalent of
public class PrintOwnSourceCode
{
public static void Main ( )
{
System.Console.WriteLine([something]);
// prints "public class PrintOwnSourceCode { public static void Main ( ) { ... } }"
}
}
???
And would that be an example of reflection?
Somewhat.
Decompilers can do something similar to this:
I just decompiled a decompiler so I could use it to decompile itself
.NET Decompilers, like [.NET Reflector] (http://www.red-gate.com/products/dotnet-development/reflector/) and dotPeek are capable of reflecting upon a .NET assembly and generating files that resemble the source code. It will not look exactly like the source code because compiling and decompiling is kind of like translating English to French and then back to English--the results are not always guaranteed to be 1:1 as Google Translate can demonstrate. Information, like whitespace, that are for easy reading but not required by the compiler will be lost in the decompilation process. So, your application could decompile itself or invoke an external decompiler to print itself.
Aside
In compiled languages, the compiled code does not have direct access to the source code. (Companies don't typically ship the source code with the compiled code to customers. They only ship the compiled executable.) When it comes to parsed languages, like JavaScript, it's a whole different story. Because the source must be available to the runtime so that it can be parsed and run, the code can always find it's own source file, open it, and print it out.
This was answered here.
The short answer is that you cannot print it via reflection.
If you want to print out the file, then you will need to load in the source file itself (and have the file available).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I search a way to convert a Group 3 compressed TIFF to png or for best in pdf with c#.net.
Try LibTiff.Net library for this.
The library comes with tiff2pdf utility (you would need to build it yourselves) that probably does exactly what you need. You may even incorporate the code of the utility in your application.
The library and utility are free and open-source. License (New BSD License) allows any modifications. You can use the library and utility in commercial applications.
Disclaimer: I am one of the maintainers of the library.
TIFF to PNG:
System.Drawing.Image will allow you to open a Group3 TIFF and save it as PNG simply by loading the TIFF as a normal image (e.g. Image.FromFile, Image.FromStream, etc.) and then saving it using the Image.Save method with the ImageFormat.Png argument. As TIFFs vary widely, on occasion I have encountered an obscure TIFF that System.Drawing won't open, but that is unusual. If it happens, you'll need to seek out a third party library from opensource (e.g. iText has a sophisticated image library) or there are commercial options such as Lead Tools or Atalasoft.
TIFF to PDF:
iTextSharp is a great library for doing this. I even found some articles on this specific topic with a google search. This one seems to be a good one to start with for your needs.
(disclaimer - I work for Atalasoft)
If you use dotImage for this, both conversions are trivial.
for tiff to pdf:
using (outputStream = new FileStream(pathToPdf, FileMode.Create)) {
PdfEncoder encoder = new PdfEncoder();
encoder.Save(outputStream, new FileSystemImageSource(pathToTiff, true), null); // true = do all pages
}
for tiff to png:
FileSystemImageSource source = new FileSystemImageSource(pathToTiff, true);
int page = 0;
while (source.HasMoreImages()) {
AtalaImage image = source[page];
using (FileStream stm = new FileStream("output_page_" + page + ".png", FileMode.Create)) {
PngEncoder encoder = new PngEncoder();
encoder.Save(stm, image, null);
}
source.Release(image);
}
Use ghostscript, i used to extract images from a PDF and create thumbnails, the lib also convert from images to PDF and it's open source.
A guy create a wrapper for the ghostscript API:
http://www.mattephraim.com/blog/2009/01/06/a-simple-c-wrapper-for-ghostscript/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I have been trying to find a code snippet to do an unsharp mask in C# but cant find one that works or is complete. I found a PHP version but I would like to find one in C# before I go through all the hard work converting this from PHP.
I am just a beginner. Can anyone point me in the right direction?
The AForge.NET Framework includes many image processing filters and support plugging your own. You can see it in action in their own Image Processing Lab application.
UPDATE: AForge.NET has a convolution-based sharpen filter (see convolution filters), but there's no mention of an unsharp mask filter per se. Then again, you can use the Gaussian blur filter and subtract the result from the original image, which is basically what the unsharp mask filter does. Or maybe the basic sharpen is enough for your needs.
UPDATE: Looked further, and AForge.NET does have a Gaussian sharpen which seems to be an implemenation of an unsharp mask filter, and you can control some parameters.
Would you care to use FFTs? Transform, remove or accentuate high freqs to taste, invert the transform, recombine with the original if desired? Hardly any licensing issues there, as FFT libraries abound.
Alternately, you can make up masks by hand, varying size and constants as you like, then convolve them with your image pixels (nested 'for' loops ...).
Here's a 3x3x1 mask as a text file with its dimensions given before the values:
//3x3x1
// x size
3
// y size
3
//z size
1
//z = 0
2 3 2
3 5 3
2 3 2
//end
This can be extended to 3 dimensions (hence the z size being given).
The latest version of the open source C# Image Library has an unsharp mask filter (as well as gaussian blur, brightness/contrast etc) and is very easy to use.
You'll find a tutorial how to apply an unsharp mask here.
See if this blog entry helps you in the right direction:
http://anand-vinay.blogspot.com/2008/01/unsharp-mask-in-cnet.html
Edit: Okay that blog entry did not work, sorry for the bad link.
I did find a complete application that you can download with source which has the code that I think you are looking for.
http://www.ctyeung.com/Csharp/index.html
Christian Graus's Image Processing for Dummies with C# part 2 contains source code, and an explanation of how you can do unsharpen (assuming you mean smoothing). The whole series is an excellent introduction to image processing with GDI (in C#) and requires no external libraries.