I'm writing a performance critical class in C# for image manipulation. I'm using LockBits to gain access to the actual data directly and all is working well but I'd like to get more info on the memory signature of certain PixelFormats, most notably Imaging.PixelFormat.Format32bppPArgb.
Anyone know a reliable website somewhere which lists these?
You will find neccessary information about image manipulation with using LockBits.
https://web.archive.org/web/20141229164101/http://bobpowell.net/lockingbits.aspx
Related
so I am trying to protect my game from memory scanners without using a server the protection doesn't need to be 100% but I want to try and protect them from most of the cheats I have an idea to try and change the address of the variable once a few seconds or maybe even on the onUpdate method but I don't know how to do that on the code without breaking the game, I know that has to be possible since there are some add-ons in the unity store that gives you classes like ProtectedInt that are like the original data types but can't be detected by software like cheat engine I can buy the addons but I wanna try to do without buying it..
is there another way I can protect my variables is my idea is possible to do without breaking or losing the value of the variable?
This is a simple little tutorial on protecting variables, prefs and such. Utilizing ILSpy for validation. It's a great read. At the least you should install ILSpy.
https://www.alanzucconi.com/2015/09/02/a-practical-tutorial-to-hack-and-protect-unity-games/
You might try using Windows Data Protection API exposed in .NET through System.Cryptography.ProtectedMemory, quick tutorial can be found here. Another writeup of the method includes a relevant note about copies of the unencrypted array being left in memory as a result of garbage collector defragmentation process.
General approach to protect different objects in your application would involve using binary de/serialization into an array, which you would then protect using the above method. Check out this answer to see how to do that. Once you have MemoryStream, use its method ToArray() to get the array.
I would like to know if there is a way that I can determine whether or not two images are the same (there are lots of posts on that topic, I know), but it's also possible that one picture is a compressed version of the other image...
This post also asks for a C# library that does image processing and comparing, but I'm not really sure what kind of functions a library would need to provide this specific match.. This post on the other hand is way to abstract.
I've read about OpenCV (or this .NET wrapper) but I have no experience with it, and I'm not sure if it will do what I want without applying the abstractions from the that post I didn't understand myself.. I mean, OpenCV is probably capable of doing the required computations, it seems like a very powerful tool, but it seems a bit complex for the seemingly simple requirement.. Or is this actually more complex and is something like OpenCV the way to go? (and if so, how?)
So, how would I go about achieving this?
One simple path you could try is AForge .NET library. It is fully .NET implementation so no worries about environment setup, and has following functionality, that might fit your case :
ExhaustiveTemplateMatching Class
"The class implements exhaustive template matching algorithm, which performs complete scan of source image, comparing each pixel with corresponding pixel of template. The class also can be used to get similarity level between two images of the same size, which can be useful to get information about how different/similar are images"
http://www.aforgenet.com/framework/docs/html/17494328-ef0c-dc83-1bc3-907b7b75039f.htm
// create template matching algorithm's instance
// use zero similarity to make sure algorithm will provide anything
ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0);
// compare two images
TemplateMatch[] matchings = tm.ProcessImage(image1, image2);
// check similarity level
if (matchings[0].Similarity > 0.95f)
{
// do something with quite similar images
}
I need to perform operations chronologically on huge time series implemented as IList. The data is ultimately stored into a database, but it would not make sense to submit tens of millions of queries to the database.
Currently the in-memory IList triggers an OutOfMemory exception when trying to store more than 8 million (small) objects, though I would need to deal with tens of millions.
After some research, it looks like the best way to do it would be to store data on disk and access it through an IList wrapper.
Memory-mapped files (introduced in .NET 4.0) seem the right interface to use, but I wonder what is the best way to write a class that should implement IList (for easy access) and internally deal with a memory-mapped file.
I am also curious to hear if you know about other ways ! I thought for example of an IList wrapper using data from db4o (someone mentionned here using a memory-mapped file as the IoAdapterFile, though using db4o probably adds a performance cost vs. dealing directly with the memory-mapped file).
I have come across this question asked in 2009, but it did not yield useful answers or serious ideas.
I found this PersistentDictionary<>, but it only works with strings, and by reading the source code I am not sure it was designed for very large datasets.
More scalable (up to 16 TB), the ESENT PersistentDictionary<>, uses the ESENT database engine present in Windows (XP+) and can store all serializable objects containing simple types.
Disk Based Data Structures, including Dictionary, List and Array with an "intelligent" serializer looked exactly like what I was looking for, but it did not run smoothly with extremely large datasets, especially as it does not make use of the "native" .NET MemoryMappedFiles yet, and support for 32 bits systems is experimental.
Update 1: I ended up implementing my own version that makes extensive use of .NET MemoryMappedFiles; it is very fast and I will probably release it on Codeplex once I have made it better for more general purpose usages.
Update 2: TeaFiles.Net also worked great for my purpose. Highly recommended (and free).
I see several options:
"in-memory-DB"
for example SQLite can be used this way - no need for any setup etc. just deploying the DLL (1 or 2) together with the app and the rest can be done programmatically
Load all data into temporary table(s) into the DB, with unknown (but big) amounts of data I found that this pays off really fast (and processing can usually be done inside the DB whcih is even better!)
use a MemoryMappedFile and a fixed structure size (array-like access via offset) but beware that physical memory is the limit except you use some sort of "sliding window" to map only parts into memory
The memory mapped files is a nice way to do it. But it going to be very slow if you need to access things randomly.
Your best bet is probably to come up with a fixed structure size when saved in memory (if you can) then you use the offset as the list item id. However deletes / sorting is always a problem.
I need to generate large images (A4 image at 200 DPI, PNG format would be fine) in my compact framework application. This is impossible to do in standard way due to memory limitations (such big image will throw OOMException).
Is there any library which offers file-backed stream image generation?
Or I could generate many smaller stripes of images (each stripe representing a row of the large image) using standard Bitmap approach, but I need to merge them together afterwards - is there any method how to merge many smaller images into one large without having to instantiate large Bitmap instance (which would again cause OOM)?
I had a similar need myself, and I end writing my own library. PNGJ You may found it useful, it's Java but it should be easy to port to C# (completely independent of other libraries). It writes and reads PNG images (except paletted ones), line oriented, rather low level, optimized for handling huge images. There are some examples in the download.
Updated: I've made a C# available here: PNGCS
This is interesting... I did some googling for you, and the only useful thing I found is this OpenNETCF Smart Device Framework. The class library reference is here Suggest you to take a look at ImagingFactoryClass. CreateImageEncoderToStream method might be useful.
Merging approach would be cool if you had a library that would do it for you. I took a look at PNG specifications and its not very promising.
Good luck and I hope this helps.
I just made a quick basic implementation of PNG stream encoding class - it supports just 8bpp and grayscale at the moment though, but that's enough for my scenario. It should be quite easy to extend the class to support RGB and more color depths.
http://gist.github.com/393409
I have two bitmaps, produced by different variations of an algorithm. I'd like to create a third bitmap by subtracting one from the other to show the differences.
How can this be done in .NET? I've looked over the Graphics class and all its options, including the ImageAttributes class, and I have a hunch it involves the color matrix or remap tables functionality.
Does anyone have a link to some example code, or can point me in the right direction? A google search doesn't reveal much, unless my google-fu is failing me today.
The real question is, what differences do you want to show? If you just need to operate on RGB color values, the best bet in my opinion is to just scan through both bitmaps and compare the Color values using GetPixel, and use SetPixel to generate your 'difference' bitmap. Perhaps you simply want to subtract the values and use those as the new Color value for the third bitmap. Or perhaps you want to calculate out the luminosity and use that. Even better, if you have three metrics for comparison, assign each one to the R G and B components of the color. I've used this approach for fractal colorization before.
There are other approaches, but with this one you are limited only to your imagination. It may not be the fastest approach, but it does not sound like performance is necessary for this scenario.
Check out this project. It is a motion detector made by Andrew Kirillov. He implements a couple of filters to get the differences between two pictures and uses that to calculate movements. It is really nice done and its easy to modify and use in your own application.
http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx
This can be done by PInvoking the BitBlt API function. Here is some sample code:
http://www.codeproject.com/KB/GDI-plus/Bitblt_wrapper_class.aspx
The sample uses the SRCCOPY raster op code; to get the differences between two bitmaps, you'd instead want to use SRCPAINT or something (GOOGLE should give the list of codes).
GetPixel and SetPixel (on the Bitmap class) are unbelievably slow. Using LockBits will be much faster, but you'll still have to write your own code.
Update: this is a better link:
http://www.pinvoke.net/default.aspx/gdi32.BitBlt
and includes all the possible ternary raster operations (SRCPAINT or SRCAND are probably what you're looking for.).
First, define subtract ;-p What do you want the answer to look like?
The most performance way to do this is probably LockBits - it should be much quicker than lots of GetPixel calls, but you'll need to decode the bytes yourself. Easy if it is just something like 32bpp ARGB, but tricky for some more complex cases.
I've read somewhere that the language used in Adobe Pixel Bender is inspired by something that Microsoft once did. Don't remember where I read it. My thinking is that maybe that Microsoft "something" is wrapped into something that a .Net project can use. Overkill for just subtracting two images, but anyway.