|
I can see that. I guess I will chalk that up to this being my first serious attempt and multithreading with the async...await model.
Currently reading Best Practices in Asynchronous Programming to get a better idea of what I am doing wrong here and what is the right way.
Any other tips to get me started would be appreciated.
Does over-complicating something simple make me an engineer?
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016
|
|
|
|
|
|
Hello,
I want to write a C# label print application. My printer is Zebra P4T. My label size is 3x3 cm one column one row. I tried some libraries, RawPrinterHelper class etc. but they didn't fit. What is your advice to start with?
Thanks.
|
|
|
|
|
|
To print to a Zebra printer, you'll need to combine the RawPrinterHelper class with ZPL commands: ZPL2 Programmers Manual[^]
Here's the class I use[^] - just call RawPrinterHelper.SendStringToPrinter(zplPrinterName, zplDocument, null) to send the specified ZPL commands to the printer.
This tool[^] lets you preview your ZPL document online, although you might find some subtle differences between the tool and your printer.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
There are some options to do it. One is that with Zebra printers you are receiving also software to create labels fe. Zebra Designer. You can create tamplate in this software, save it as text file (it will be ZPL language) and in your application you will read this template then you will do string replace with your data and send it all as text to the printer. Other option is to generate pdf file in your app and send pdf file with your label to printer. But printer will need to support it.
|
|
|
|
|
i have seen some people post the bench mark graph for their c# application. suppose a routine is parsing large csv file. so people post bench mark graph to show how routine is efficient to read large csv file with very minimum time. is it possible to generate bench mark graph from VS2013 or VS2015 IDE ?
please share the idea. thanks
tbhattacharjee
|
|
|
|
|
Effectively you need two parts to perform the benchmarking. The first is a timer that you use to log the difference between the start of the operation and the time it ends (it's worth looking at the Stopwatch class here - don't use DateTime to do this). Then you need to run the code you want to benchmark many, many times. I would typically start by thinking that the benchmark should exercise the code about 10K times.
When you run the code, run it on a machine that isn't doing anything else. Better still - run it on several machines of different configurations so that you can get an idea of how things such as processor power, memory, etc, have an effect.
This space for rent
|
|
|
|
|
I reliazed a visual program using huffman algorithm for txt files.I can easily compress txt files but ı cannot compress image.Huffman is text-based algorithm.How I can do it using huffman algorithm using c#?
|
|
|
|
|
A quick search brought up Huffman coding in C#[^]. This might be a good place for you to start.
This space for rent
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace HuffmanTest
{
class Program
{
static void Main(string[] args)
{
string input = "foo bar";
HuffmanTree huffmanTree = new HuffmanTree();
// Build the Huffman tree
huffmanTree.Build(input);
// Encode
BitArray encoded = huffmanTree.Encode(input);
Console.Write("Encoded: ");
foreach (bool bit in encoded)
{
Console.Write((bit ? 1 : 0) + "");
}
Console.WriteLine();
// Decode
string decoded = huffmanTree.Decode(encoded);
Console.WriteLine("Decoded: " + decoded);
Console.ReadLine();
}
}
}
Here input is "foo bar"; which is string.Input will be image.
|
|
|
|
|
So just read the image into your application, as you have been told many times already. Text, image, audio, video - they are all the same, just streams of bytes.
|
|
|
|
|
I used base64 but image file 10 mb and then base64 string 16 mb and compress by huffman this base64 string result is 12 mb .
|
|
|
|
|
That is not unusual, since image files tend to be difficult to compress. And .jpg files are already compressed.
|
|
|
|
|
If you want to test your algorithm out on an image, I would suggest that you try it against a RAW image file. RAW does what it says - it provides the raw data so you can test your compression against uncompressed data.
This space for rent
|
|
|
|
|
Just pass the bytes representing the image to the encoder. If your input parameter is actually a string, replace it by passing a byte array and the length and adapt the code as necessary (replace char by byte and use the passed length instead of the string length). Just think of a string as an array of charaters (one or two bytes per character) and a length. Then you will recognise that there is no big difference (no difference at all when the string class uses one byte per character).
|
|
|
|
|
I tried.But ı was not succesful May you help me ?.I am not good in c#.I am new.I want to do this ı want to understand.Can ı send you my project ?
|
|
|
|
|
Post the relevant (short) code snippets here (you can edit your initial question and add it there) and explain what you have tried and where you got stuck. So you will get the best help because many people can read it.
|
|
|
|
|
I am not good c# actually.I reliazed huffman with c# but whihc compress only text. not image.how can ı do that.İf you want ı can sedn my project MAybe you can help me
|
|
|
|
|
I'm sorry but I did not provide private help here (and others won't do it too). This is a public forum where questions are answered public.
So follow my advices from my previous post and provide more details.
|
|
|
|
|
[Huffman Compressor]
My program is blow the link.This program only comrpess text.What do ı add this program and then which can compress an image for example jpeg.May you investigate my program
|
|
|
|
|
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.
|
|
|
|