Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. JPEG image processing with C#

JPEG image processing with C#

Scheduled Pinned Locked Moved C#
helpcsharpquestionlearning
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    memoboy
    wrote on last edited by
    #1

    Hi every one I need a help in JPEG image processing with C# language ,I need to know how can I read the jpeg file bit’s in the stream wile it compressed and get from it each pixel value in jpeg pixel format and then convert this pixel from jpeg format into RGB format and return it for the jpeg format ,if that is possible. I really need a help on this I search a lot for this but nothing I get ,if any one have any idea or resource about this problem pleas tell me about it ,if you can. memo

    C H M 3 Replies Last reply
    0
    • M memoboy

      Hi every one I need a help in JPEG image processing with C# language ,I need to know how can I read the jpeg file bit’s in the stream wile it compressed and get from it each pixel value in jpeg pixel format and then convert this pixel from jpeg format into RGB format and return it for the jpeg format ,if that is possible. I really need a help on this I search a lot for this but nothing I get ,if any one have any idea or resource about this problem pleas tell me about it ,if you can. memo

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      What you're asking is kind of bizarre. A JPEG is compressed, you can't read it bit by bit to get the pixel values, you need to decompress it. Luckily, the Bitmap::FromFile function will do this for you for free. All you need to do is load the jpeg from disc, and then use the approach seen in my image processing articles here on code project to access the bits. Remember, if you're going to edit a jpg, jpg has lossy compression, so some detail is lost when you save it again. To summarise, you need to load the entire jpeg, edit it as an in memory bitmap, and save it again as a jpeg. No compression scheme will allow you to change one pixel without changing significantly more than one byte of the image in it's compressed format. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

      M 1 Reply Last reply
      0
      • M memoboy

        Hi every one I need a help in JPEG image processing with C# language ,I need to know how can I read the jpeg file bit’s in the stream wile it compressed and get from it each pixel value in jpeg pixel format and then convert this pixel from jpeg format into RGB format and return it for the jpeg format ,if that is possible. I really need a help on this I search a lot for this but nothing I get ,if any one have any idea or resource about this problem pleas tell me about it ,if you can. memo

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        And to add what Christian said, use Bitmap.LockBits to get the BitmapData in which you process each pixel, and Bitmap.UnlockBits to release the lock (locks the data in memory so it isn't moved while processing it) on the bits. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

        C 1 Reply Last reply
        0
        • M memoboy

          Hi every one I need a help in JPEG image processing with C# language ,I need to know how can I read the jpeg file bit’s in the stream wile it compressed and get from it each pixel value in jpeg pixel format and then convert this pixel from jpeg format into RGB format and return it for the jpeg format ,if that is possible. I really need a help on this I search a lot for this but nothing I get ,if any one have any idea or resource about this problem pleas tell me about it ,if you can. memo

          M Offline
          M Offline
          memoboy
          wrote on last edited by
          #4

          ok but as i know if i open the image and modefy it bit's in bitmabe formate and then i restore it as jpeg foramte there will be a lose in bit's value my project need from me to keep some spacifice bit's in each pixel with keeping it in it origonal form without losing it there is any way for that memo

          C 1 Reply Last reply
          0
          • H Heath Stewart

            And to add what Christian said, use Bitmap.LockBits to get the BitmapData in which you process each pixel, and Bitmap.UnlockBits to release the lock (locks the data in memory so it isn't moved while processing it) on the bits. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            *grin* I was hoping he'd get that bit from my articles :-) Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

            1 Reply Last reply
            0
            • M memoboy

              ok but as i know if i open the image and modefy it bit's in bitmabe formate and then i restore it as jpeg foramte there will be a lose in bit's value my project need from me to keep some spacifice bit's in each pixel with keeping it in it origonal form without losing it there is any way for that memo

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              memoboy wrote: ok but as i know if i open the image and modefy it bit's in bitmabe formate and then i restore it as jpeg foramte there will be a lose in bit's value Yep, like I said, that's what 'lossy compression' means. memoboy wrote: my project need from me to keep some spacifice bit's in each pixel with keeping it in it origonal form without losing it there is any way for that You want jpeg compression to be lossless ? No, you can't achieve that, you need to use a different image format. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

              H 1 Reply Last reply
              0
              • C Christian Graus

                What you're asking is kind of bizarre. A JPEG is compressed, you can't read it bit by bit to get the pixel values, you need to decompress it. Luckily, the Bitmap::FromFile function will do this for you for free. All you need to do is load the jpeg from disc, and then use the approach seen in my image processing articles here on code project to access the bits. Remember, if you're going to edit a jpg, jpg has lossy compression, so some detail is lost when you save it again. To summarise, you need to load the entire jpeg, edit it as an in memory bitmap, and save it again as a jpeg. No compression scheme will allow you to change one pixel without changing significantly more than one byte of the image in it's compressed format. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                M Offline
                M Offline
                memoboy
                wrote on last edited by
                #7

                hi thanks you very much for answering me. I will explain my problem , and why I want to do this bizarre ;) thing ,this problem come from my project where I try to hide some kind of data in all the byte’s in the image pixel’s without insert any noise for the image colour and it worked with me in the bitmap format (RGB) ,but I try now to drive my algorithm to work on the jpeg format either but I found a lot of problem on this that because. I couldn’t understand for this time how the jpeg compressed ,and how it store each compressed pixel in the jpeg file ,and how could I get this stored pixel and returned it into RGB format and work my algorithm with it and then return it into JPEG format and store it that only if that could be possible ,you can see that my problem come from ,that I still try to understand the JPEG image format but I tried very much to solve this problem but nothing helped me because I couldn’t find a good resource about this subject. So as you said “If you're going to edit a jpg, jpg has lossy compression, so some detail is lost when you save it again “ and I want for this to be happen because any bit I loss it could cause for me a disaster. I don’t ask here to tell me if there is any ready library can help me to do this I just want to know does that possible to be happen or not? And if it can be , how?? I believe that all the programming is just a game nothing more or less. Thanks again for every one give me a suggestion that can help me to solve this bizarre problem. i try to learn programming what ever i had i feal that i did'nt get anything

                L B C 3 Replies Last reply
                0
                • M memoboy

                  hi thanks you very much for answering me. I will explain my problem , and why I want to do this bizarre ;) thing ,this problem come from my project where I try to hide some kind of data in all the byte’s in the image pixel’s without insert any noise for the image colour and it worked with me in the bitmap format (RGB) ,but I try now to drive my algorithm to work on the jpeg format either but I found a lot of problem on this that because. I couldn’t understand for this time how the jpeg compressed ,and how it store each compressed pixel in the jpeg file ,and how could I get this stored pixel and returned it into RGB format and work my algorithm with it and then return it into JPEG format and store it that only if that could be possible ,you can see that my problem come from ,that I still try to understand the JPEG image format but I tried very much to solve this problem but nothing helped me because I couldn’t find a good resource about this subject. So as you said “If you're going to edit a jpg, jpg has lossy compression, so some detail is lost when you save it again “ and I want for this to be happen because any bit I loss it could cause for me a disaster. I don’t ask here to tell me if there is any ready library can help me to do this I just want to know does that possible to be happen or not? And if it can be , how?? I believe that all the programming is just a game nothing more or less. Thanks again for every one give me a suggestion that can help me to solve this bizarre problem. i try to learn programming what ever i had i feal that i did'nt get anything

                  L Offline
                  L Offline
                  leppie
                  wrote on last edited by
                  #8

                  I suggest you go with PNG instead. It really depends what type of images you are working with though... top secret
                  Download xacc-ide 0.0.3 now!
                  See some screenshots

                  1 Reply Last reply
                  0
                  • M memoboy

                    hi thanks you very much for answering me. I will explain my problem , and why I want to do this bizarre ;) thing ,this problem come from my project where I try to hide some kind of data in all the byte’s in the image pixel’s without insert any noise for the image colour and it worked with me in the bitmap format (RGB) ,but I try now to drive my algorithm to work on the jpeg format either but I found a lot of problem on this that because. I couldn’t understand for this time how the jpeg compressed ,and how it store each compressed pixel in the jpeg file ,and how could I get this stored pixel and returned it into RGB format and work my algorithm with it and then return it into JPEG format and store it that only if that could be possible ,you can see that my problem come from ,that I still try to understand the JPEG image format but I tried very much to solve this problem but nothing helped me because I couldn’t find a good resource about this subject. So as you said “If you're going to edit a jpg, jpg has lossy compression, so some detail is lost when you save it again “ and I want for this to be happen because any bit I loss it could cause for me a disaster. I don’t ask here to tell me if there is any ready library can help me to do this I just want to know does that possible to be happen or not? And if it can be , how?? I believe that all the programming is just a game nothing more or less. Thanks again for every one give me a suggestion that can help me to solve this bizarre problem. i try to learn programming what ever i had i feal that i did'nt get anything

                    B Offline
                    B Offline
                    benjymous
                    wrote on last edited by
                    #9

                    memoboy wrote: ..I try to hide some kind of data.. You mean steganography? Corinna John has written a long series of articles on that subject here on CP: Clicky[^] -- Help me! I'm turning into a grapefruit! Phoenix Paint - back from DPaint's ashes!

                    M 1 Reply Last reply
                    0
                    • B benjymous

                      memoboy wrote: ..I try to hide some kind of data.. You mean steganography? Corinna John has written a long series of articles on that subject here on CP: Clicky[^] -- Help me! I'm turning into a grapefruit! Phoenix Paint - back from DPaint's ashes!

                      M Offline
                      M Offline
                      memoboy
                      wrote on last edited by
                      #10

                      you what are you saying about the steganography and what corinna john did about it she provide a very wonderful work ,I have been read all of it work and I like it very much but in my project I use another algorithm which allow for me to hide a huge mountain of bit's in each pixel without insert any noise on the image it self ,but as I have seen in corinna work the passward control the a mount of bit's that you can hide in the image ,my algorithm allow for me to hide in all the pixel. And that is a very big different here. i try to learn programming what ever i had i feal that i did'nt get anything

                      1 Reply Last reply
                      0
                      • C Christian Graus

                        memoboy wrote: ok but as i know if i open the image and modefy it bit's in bitmabe formate and then i restore it as jpeg foramte there will be a lose in bit's value Yep, like I said, that's what 'lossy compression' means. memoboy wrote: my project need from me to keep some spacifice bit's in each pixel with keeping it in it origonal form without losing it there is any way for that You want jpeg compression to be lossless ? No, you can't achieve that, you need to use a different image format. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                        H Offline
                        H Offline
                        Heath Stewart
                        wrote on last edited by
                        #11

                        JPEG2000 claims to support lossless compression, but GDI+ does not support it yet in any release bits. If one could find a GDI+ image codec then .NET would inherit the format by instantiating your own ImageFormat using whatever Guid defined with such a codec. To the original poster, if you want lossless compression PNG is about as close as you'll get. You can also control the amount of compression (less compression == better quality == larger file size) by using the Save override to specify an EncoderParameters object and using the EncoderValue enumeration with one of the compression members if you save as a TIFF image (.tif or .tiff). This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

                        1 Reply Last reply
                        0
                        • M memoboy

                          hi thanks you very much for answering me. I will explain my problem , and why I want to do this bizarre ;) thing ,this problem come from my project where I try to hide some kind of data in all the byte’s in the image pixel’s without insert any noise for the image colour and it worked with me in the bitmap format (RGB) ,but I try now to drive my algorithm to work on the jpeg format either but I found a lot of problem on this that because. I couldn’t understand for this time how the jpeg compressed ,and how it store each compressed pixel in the jpeg file ,and how could I get this stored pixel and returned it into RGB format and work my algorithm with it and then return it into JPEG format and store it that only if that could be possible ,you can see that my problem come from ,that I still try to understand the JPEG image format but I tried very much to solve this problem but nothing helped me because I couldn’t find a good resource about this subject. So as you said “If you're going to edit a jpg, jpg has lossy compression, so some detail is lost when you save it again “ and I want for this to be happen because any bit I loss it could cause for me a disaster. I don’t ask here to tell me if there is any ready library can help me to do this I just want to know does that possible to be happen or not? And if it can be , how?? I believe that all the programming is just a game nothing more or less. Thanks again for every one give me a suggestion that can help me to solve this bizarre problem. i try to learn programming what ever i had i feal that i did'nt get anything

                          C Offline
                          C Offline
                          Christian Graus
                          wrote on last edited by
                          #12

                          I guessed this is what you were doing, image masking is why I almost never use jpeg, for exactly this reason. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups