Results 1 to 9 of 9

Thread: How to implement huffman algorithm for image

  1. #1
    calculus67 is offline C# Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2016
    Posts
    9
    Rep Power
    0

    How to implement huffman algorithm for image

    I coded a visual c# program using huffman for txt files.I can easily compress all txt files.But ı want to compress image.My program take a txt files and compress then output format is .huf also ı can deceompress it.But how can ı do it for image ?

  2. #2
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,435
    Rep Power
    116
    You can read the image into a byte array and convert that to a base64 string. Then it's just text like any other, so you can use the method you already have to encode it.

  3. #3
    calculus67 is offline C# Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2016
    Posts
    9
    Rep Power
    0
    how to convert may you give an example.For image compressing can ı need to change my all codes ?

  4. #4
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,435
    Rep Power
    116
    Quote Originally Posted by calculus67 View Post
    how to convert may you give an example.
    What do you not understand about the examples you found when you searched the web?
    Quote Originally Posted by calculus67 View Post
    For image compressing can ı need to change my all codes ?
    If you had to change everything then I wouldn't have said this:
    Then it's just text like any other, so you can use the method you already have to encode it.
    If you have a method that takes an unencoded string as an argument and returns an encoded string then it doesn't matter where the unencoded string comes from. It could be the contents of a text file or it could be the result of passing a byte array to Convert.ToBase64String. A String is a String, regardless of its source.

  5. #5
    calculus67 is offline C# Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2016
    Posts
    9
    Rep Power
    0
    Quote Originally Posted by jmcilhinney View Post
    What do you not understand about the examples you found when you searched the web?

    If you had to change everything then I wouldn't have said this:If you have a method that takes an unencoded string as an argument and returns an encoded string then it doesn't matter where the unencoded string comes from. It could be the contents of a text file or it could be the result of passing a byte array to Convert.ToBase64String. A String is a String, regardless of its source.
    My program take txt files and read all characters.Program doesnt encoded character.Program encoded characher's Ascii code.Sorry I am not very good in c#.I need someone show how to do it.I hope you may help me.My program's link is above.Thank you.

    https://drive.google.com/open?id=0Bz...1k3SVowR1Q0QU0

  6. #6
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,435
    Rep Power
    116
    Quote Originally Posted by calculus67 View Post
    Program doesnt encoded character.Program encoded characher's Ascii code.
    It doesn't matter. You're still starting with text. It doesn't matter whether that text comes from a text file or the result of converting a byte array to a base64 string. Text is text.

    I'm not here to write your code for you. We're none of us very good at programming when we start but we get better by doing it. I've told you what to do. Now it's time for you to do it. You can't succeed if you don't. If you try and it doesn't work then I will help you fix the issues but I'm not going just do it for you so that you don't have to try.

  7. #7
    calculus67 is offline C# Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2016
    Posts
    9
    Rep Power
    0
    Quote Originally Posted by jmcilhinney View Post
    It doesn't matter. You're still starting with text. It doesn't matter whether that text comes from a text file or the result of converting a byte array to a base64 string. Text is text.

    I'm not here to write your code for you. We're none of us very good at programming when we start but we get better by doing it. I've told you what to do. Now it's time for you to do it. You can't succeed if you don't. If you try and it doesn't work then I will help you fix the issues but I'm not going just do it for you so that you don't have to try.
    I must do like that given the link ?.An image file convert to base 64 then program take base64 strings decode processing is opposite of encode .
    https://www.youtube.com/watch?v=P0UJ6ob4I5k

  8. #8
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,435
    Rep Power
    116
    I'm not going to be watching any videos. If there's anything I need to know then explain it. What you need to do is write a method that takes an unencoded String and returns encoded data. You can then call that method and pass any string you want, e.g. the contents of a text file or the result of calling Convert.ToBase64String with the a byte array obtained from an image. It requires very little effort to find out how to get a byte array from an image file or an Image object from the web. You've now wasted 24 hours when you should have done that when I first told you that it's what is required. I will not be contributing any further until I see some effort in that direction.

  9. #9
    calculus67 is offline C# Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2016
    Posts
    9
    Rep Power
    0
    Quote Originally Posted by jmcilhinney View Post
    I'm not going to be watching any videos. If there's anything I need to know then explain it. What you need to do is write a method that takes an unencoded String and returns encoded data. You can then call that method and pass any string you want, e.g. the contents of a text file or the result of calling Convert.ToBase64String with the a byte array obtained from an image. It requires very little effort to find out how to get a byte array from an image file or an Image object from the web. You've now wasted 24 hours when you should have done that when I first told you that it's what is required. I will not be contributing any further until I see some effort in that direction.

    I converted and image to basestring64 but ı have a problem like this.For example an image file is 10 mb after convert with base64 text size is 14 mb this text is compressed by huffman then result is 12 mb.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •