|
Rıza Berkay Ayçelebi wrote: This program only comrpess text. It works the same for any set of bytes, so it will not "just work" on text only. Text, pictures, sounds, applications; all just a series of bytes.
You still have not answered my question
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
I want to compress picture.I compressed text wiht huffman but how can ı do for pictures ?
|
|
|
|
|
There are problems.
I see that you store the frequency of characters in the header as bytes. That's wrong on both counts. You shouldn't store the frequency because there are multiple valid Huffman trees for almost every set of frequencies (you should therefore, and every format that uses Huffman codes does this, use Canonical Huffman codes[^] and store only the symbol lengths). Storing the frequency as a byte will obviously fail for larger files - images are likely to be large, but this wouldn't have worked for large text files either. Of course if you change to canonical codes and storing the symbol length, it will fit in a byte just fine.
Now moving on to things that aren't actually incorrect but are point for improvement, you don't need (and therefore shouldn't use) single-bit reads and writes. For encoding, just collect the pattern/length of every symbol in a little array and then use something like (not tested, just to get the idea)
uint buffer = 0;
int bitsInBuffer = 0;
foreach (var symbol in imageOrWhatever) {
buffer = (buffer << lengths[symbol]) | pattern[symbol];
bitsInBuffer += lengths[symbol];
while (bitsInBuffer >= 8) {
output.WriteByte((byte)(buffer >> (bitsInBuffer - 8));
bitsInBuffer -= 8;
}
}
Or you can change it to not even do byte-IO either and do proper block IO. This code of course assumes that codes are 25 bits max (otherwise appending a code to the buffer can push something out that hasn't been saved), which is longer than you need, but you could use an ulong as buffer.
For decoding you can use a (big) array that has, for every index, what the first symbol (and its length) are if the index is interpreted as a string of Huffman encoded symbols. This array is easy to build and even easier to use, but depending on your maximum code length it can get pretty big. There are more sophisticated techniques that get the size of the array down, but it's a good start.
This sort of thing is why formats that use Huffman coding specify a maximum code length that isn't too long, for example DEFLATE allows lengths up to and including 15 bits.
|
|
|
|
|
how ı can change sorry ı am not very good in c#
|
|
|
|
|
Your C# skill isn't really the problem here. The problems are more fundamental.
|
|
|
|
|
I am not good in c# I said aldready.But I can create program with c#.I want someone shows how to do it over my codes.I aldready sent my project.My project only take text.
|
|
|
|
|
..works only for text, because you are feeding it a string. You can feed it any bytes, but most images are already compressed - so yes, the result would often be larger than what you started with.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Did you even look at the link I put above?
This space for rent
|
|
|
|
|
I saw the link.I dont have a problems how to code huffman .I aldready coded but ı didnt comrpess image.Can this huffman code compress an image ?
|
|
|
|
|
You obviously didn't read the link. It's encoding images.
This space for rent
|
|
|
|
|
I aldready created huffman code just ı want to learn why my codes compress only text.Can ı use your codes?
|
|
|
|
|
What do you mean with "cannot compress image"? What kind of image? How large, how many colors?
Something like a jpg would already be compressed, so I would not be surprised if it does not actually compress much there.
If you have a bitmap with large repeating spaces, then huff may puff a few bits of it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
As Eddy has already said: most images are already compressed, and pretty solidly. Compressing compressed data rarely achieves significant result, and often increases the size of the output file, due to the overhead the compression algorithm has to add.
And if you think anyone is going to download your whole project just to tell you that again, you need to rethink your position in the world - it's not as high as you seem to believe...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Rıza Berkay Ayçelebi wrote: I can comrpess text wiht this program but how can ı compres picture ? You compress pictures in the same way as text.
The computer does not distinguish between text and pictures on that level. You may be interested in the Wikipedia articles that explain how JPEG works, since it is a different approach to achieve a similar endresult.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In my current project, I need to do some calculations in 3d space, like calculating intersection points of lines with planes, determining if a point is inside a triangle / rectangle / (flat) polygone etc.
The Systems.Windows.Media.Media3D namespace offers some functionality for those purposes like cross and dot products of 3d vectors. Sadly, I cannot find good tutorials on the functionality of that namespace - most tutorials deal with drawing which is not relevant for me. And many Google searches point to functionality of the Xna namespace - which seems unavailable on Windows 8 / 10.
Are there other "common" namespaces in the .Net framework for such calculations?
Or do you know good tutorials for calculations with Media3d?
|
|
|
|
|
You might want to look at Math.NET[^] - particularly Math.NET Spatial[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks. That looks great. I will delve into it.
|
|
|
|
|
In C#, suppose you have the variable dt type DataTable and a loaded list of employees for variable dt, the question of his possible save data directly from the variable dt down Table data access in 2000, ie not using the loop to add new users each data record access, no other way to save the quicker this way ? in SQL Server have command in order SqlBulkCopy so Access2000 command similar this?
|
|
|
|
|
Access does not support Bulk operations.
You can use a OleDataAdapter to manage saving the changes to the DataTable back to the database, but it's also going to do it one row at a time.
|
|
|
|
|
I want to make program in C# that shows system information of PC.How can I get all this information for PC like: OS version,cpu info,cpu temperature....
https://postimg.org/image/4pyh4xbwl/
https://postimg.org/image/u5t2epylb/
https://postimg.org/image/5dtg7hhen/
https://postimg.org/image/yhho3q5i7/
https://postimg.org/image/cwclg48rj/
https://postimg.org/image/79g8in68v/
https://postimg.org/image/cywh2ycf3/
https://postimg.org/image/jdvhzmj4v/
https://postimg.org/image/hncgy51lr/
https://postimg.org/image/6p17fyd0f/
https://postimg.org/image/5b9kkndr3/
|
|
|
|
|
|
Use WMI to get the information
In your class define following const
const string WMI_SCOPE = "root\\CIMV2";
const string WMI_CLS_Win32_ComputerSystem = "Win32_ComputerSystem";
const string WMI_CLS_Win32_OperatingSystem = "Win32_OperatingSystem";
const string WMI_CLS_Win32_VideoController = "Win32_VideoController";
const string WMI_CLS_Win32_Processor = "Win32_Processor";
try
{
string sQuery = string.Format("SELECT * FROM {0}", WMI_CLS_Win32_OperatingSystem);
ObjectQuery objectQuery = new ObjectQuery(sQuery);
ManagementScope managementScope = new ManagementScope(WMI_SCOPE);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope, objectQuery);
ManagementOperationObserver results = new ManagementOperationObserver();
results.ObjectReady += new ObjectReadyEventHandler(ManagementObjectResultReady);
results.Completed += new CompletedEventHandler(ManagementObjectResultCompleted);
searcher.Get(results);
}
catch (....)
You will get wmi results in ManagementObjectResultReady event handler. Hope this helps.
|
|
|
|
|
I have a class like so:
public class BaseRef
{
public int id {get; set;}
public string listID {get; set;}
public string Name {get; set;}
}
And have a data column that is of type BaseRef that I added to a DataTable:
this.Columns.Add(new DataColumn("ParentRef", typeof(BaseRef)));
I am using OdbcDataAdapter to get a query, but in this case my query has three separate columns for the id, listID and Name fields of the Parent:
SELECT id, listID, Name FROM ParentTable
I tried to setup a DataAdapterTableMapping and add ColumnMappings, but it doesn't appear that I can map a source column to a property of a class column. I tried:
mapping.ColumnMappings.Add("id", "ParentRef.id");
mapping.ColumnMappings.Add("listID", "ParentRef.listID");
mapping.ColumnMappings.Add("Name", "ParentRef.Name");
Is there a way to get the mapping to map to the properties of my class?
|
|
|
|