14 Replies Latest reply on Aug 14, 2011 7:07 PM by studio ludens

    Set DPI from AIR'S Capturing Image.

    Mohit M Chavda Level 1

      Hi,

       


      When i capture Bitmap and saved using JPEGEncoder / PNGEncoder  i get image's dpi is 96 ( may be it's depend's on hardware resolutions any my pc have max of this).

       

      But i want to to set this dpi so in output image's as userdefined.

      Like this facility is available in photoshop so we can set dpi and size so in same size we get different dpi's image's.

       


      Is any body help me to solve out this issue.

       


      Thanks,
      Mohit.

        • 1. Re: Set DPI from AIR'S Capturing Image.
          chris.campbell Adobe Employee

          Hi Mohit,

          I'm not sure how you're capturing your image, but if you're using mx.graphics.ImageSnapshot, captureImage takes in a DPI parameter.  Is this value ignored when saving the jpg out to disk?

           

          Another alternative might be to call an external image library via native process.  I'm attaching a Windows specific project that uses the ImageMagick library.  It allows you to specify an input and output file and a target dpi, once the convert button is pressed the ImageMagick "convert.exe" command line utility is called and the image is processed.

           

          Hope this helps,

          Chris

          • 2. Re: Set DPI from AIR'S Capturing Image.
            Mohit M Chavda Level 1

            Hi Chris,

             

            Thanks for your help.

             

            Here my code is like this:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
                width="100%" height="100%" applicationComplete="appcomp()">
            <mx:Script>
                <![CDATA[
                    import mx.controls.Alert;
                    import mx.graphics.codec.JPEGEncoder;
                    import mx.graphics.ImageSnapshot;

                      private var setDPI:Number = 70;
                    private function appcomp():void
                    {
                      var imgsnap:ImageSnapshot = ImageSnapshot.captureImage(vb,setDPI,new JPEGEncoder(),false);
                        if(imgsnap && imgsnap.data is ByteArray)
                        {
                            var ba:ByteArray = imgsnap.data as ByteArray;
                            if(ba)
                            {
                                var thumbFileSingle1:File = File.applicationDirectory.resolvePath("c:/img.jpeg");           
                                var thumbFSSingle1:FileStream = new FileStream();
                                thumbFSSingle1.open(thumbFileSingle1, FileMode.WRITE);
                                thumbFSSingle1.writeBytes(ba);
                                thumbFSSingle1.close();
                            }
                        }
                       
                    }
                ]]>
            </mx:Script>
            <mx:VBox id="vb" width="200" height="200" horizontalAlign="center" verticalAlign="middle" backgroundColor="#0f0f0f">
                <mx:Text text="PRINT AT 300 DPI" color="#FFFFFF"/>
            </mx:VBox>   
            </mx:WindowedApplication>

             


            But the internal captureImage is only resize the image. Is there any way so we set dpi and size using adobe's sdk ?.

             

            And yes i check your example and it's working for me , can i use this one for mac os also ?  because my application is also run on mac os.

             


            Thanks,
            Mohit.

            • 3. Re: Set DPI from AIR'S Capturing Image.
              chris.campbell Adobe Employee

              Hi Mohit,

              I got the same results as you, my image was saved by the JPEGEncoder with 72 dpi, regardless of what DPI was captured initially.  I don't believe this is an AIR specific issue, as I've seen other people asking how to change the DPI for Flash on the web.  Would you mind reposting this question over on the AS3 forum?

               

              If you're interested in the ImageMagick solution, there is indeed a Mac binary (along with linux.)  I'd recommend checking out their website.

               

              If you haven't already, you'll also want to get familiar with AIR's native installer, which is required when you use a native process in AIR.

               

              Thanks,

              Chris

              • 4. Re: Set DPI from AIR'S Capturing Image.
                Mohit M Chavda Level 1

                Hi ,

                 

                I think this is the issue so if i give any dpi then my image is saved in same dpi as saved before i can' t change saved image's dpi like you can give solutions using ImageMagic.

                 

                If you think that in AS3 forum i will get answer then please move this / post this in AS3 forum.

                 

                Thanks for your help.
                Mohit.

                • 5. Re: Set DPI from AIR'S Capturing Image.
                  chris.campbell Adobe Employee

                  Hi Mohit,

                  I think the AS3 forum is the best bet, but unfortunately I don't have the ability to move a post to that location.  I can only move within the AIR forums, but since this isn't an air bug per say, I can at least move it to the AIR development forum where more people might be able to provide suggestions.

                   

                  Chris

                  • 6. Re: Set DPI from AIR'S Capturing Image.
                    gabrieldavis321

                    in order to modify the output DPI you will need to get the as3corelib-.93 (just google "as3corelib-.93")

                    in there you will find the class JPGEncoder.as

                     

                    you then need to modify these lines from

                     

                       writeByte(0); // = "JFIF",'\0'
                       writeByte(1); // versionhi
                       writeByte(1); // versionlo
                       writeByte(0); // xyunits
                       writeWord(1); // xdensity
                       writeWord(1); // ydensity
                       writeByte(0); // thumbnwidth
                       writeByte(0); // thumbnheight

                     

                    to

                     

                    writeByte(0); // = "JFIF",'\0'
                       //writeByte(2)
                       //trace("writing the JFIF 2")
                       writeByte(1); // versionhi
                       writeByte(1); // versionlo
                       //writeByte(0); // xyunits
                       writeByte(1); // xyunits
                       //writeWord(1); // xdensity
                       //writeWord(1); // ydensity
                       writeWord(outputImageDPI); // xdensity
                       writeWord(outputImageDPI); // ydensity
                       writeByte(0); // thumbnwidth
                       writeByte(0); // thumbnheight

                     

                    where outputImageDPI  is a variable that you pass in.

                     

                    To see a working version of this (and shamelessly plug all my hard work)  to to http://nikkosart.com//nikkoImage/testDrive.cfm

                    • 7. Re: Set DPI from AIR'S Capturing Image.
                      gabrieldavis321 Level 1

                      in order to modify the output DPI you will need to get the as3corelib-.93 (just google "as3corelib-.93")

                      in there you will find the class JPGEncoder.as

                       

                      you then need to modify these lines from

                       

                         writeByte(0); // = "JFIF",'\0'
                         writeByte(1); // versionhi
                         writeByte(1); // versionlo
                         writeByte(0); // xyunits
                         writeWord(1); // xdensity
                         writeWord(1); // ydensity
                         writeByte(0); // thumbnwidth
                         writeByte(0); // thumbnheight

                       

                      to

                       

                      writeByte(0); // = "JFIF",'\0'
                         //writeByte(2)
                         //trace("writing the JFIF 2")
                         writeByte(1); // versionhi
                         writeByte(1); // versionlo
                         //writeByte(0); // xyunits
                         writeByte(1); // xyunits
                         //writeWord(1); // xdensity
                         //writeWord(1); // ydensity
                         writeWord(outputImageDPI); // xdensity
                         writeWord(outputImageDPI); // ydensity
                         writeByte(0); // thumbnwidth
                         writeByte(0); // thumbnheight

                       

                      where outputImageDPI  is a variable that you pass in.

                       

                      To see a working version of this (and shamelessly plug all my hard work)  to to http://nikkosart.com//nikkoImage/testDrive.cfm

                      1 person found this helpful
                      • 8. Re: Set DPI from AIR'S Capturing Image.
                        Mohit M Chavda Level 1

                        Hi,

                         

                        Thanks for reply.
                        Your give good solutions and i test it.
                        Here ony the the image's parameter is set as given dpi but internally image's size is same so we only see from mouse over or on image property that image's DPI is like 300 (as per given in JPGEncoder). But in original bitmap is not change.

                         

                        I compare on this way  72 dpi , 300 dpi , 500 dpi. all have same size and same bitmap only i see that image property is set as per given dpi.

                         

                        is there any way to set dpi on  image's as magicimage library or photoshop is given ?
                        can we apply your solution in pngencoder ?

                         


                        By the way your answer is also helpful to me to undersand jpgencoder structure.

                         

                        Thanks once again.

                         

                        Mohit

                        • 9. Re: Set DPI from AIR'S Capturing Image.
                          gabrieldavis321 Level 1

                          Mohit,

                           

                          The images appear the same size on the computer screen because they are a certain pixel high and wide... but when you print the 72 image it will be much larger than than the 300 dpi image ... DPI is only used by the printer to know how many dots per inch (more dots smaller better definition image).... it is not used by computer screens.

                           

                          Can you please do me a favor... please download the evaluation version of http://nikkosArt.com/nikkoImage and let me know what you think.  Please tell me anything that can make it better.

                           

                          By the way NikkoImage lets you control the output scale of your image... so you can have a web page where the image is 300px but you can have it output a 600 px image (in other words make the picture bigger as you increase the output DPI).

                           

                          Thanks!

                          Gabriel

                           

                           

                          Date: Thu, 3 Feb 2011 00:11:41 -0700

                          From: forums@adobe.com

                          To: gdavis321@hotmail.com

                          Subject: Set DPI from AIR'S Capturing Image.

                           

                          Hi,

                           

                          Thanks for reply.

                          Your give good solutions and i test it.

                          Here ony the the image's parameter is set as given dpi but internally image's size is same so we only see from mouse over or on image property that image's DPI is like 300 (as per given in JPGEncoder). But in original bitmap is not change.

                           

                          I compare on this way  72 dpi , 300 dpi , 500 dpi. all have same size and same bitmap only i see that image property is set as per given dpi.

                           

                          is there any way to set dpi on  image's as magicimage library or photoshop is given ?

                          can we apply your solution in pngencoder ?

                           

                           

                          By the way your answer is also helpful to me to undersand jpgencoder structure.

                           

                          Thanks once again.

                           

                          Mohit

                          >

                          • 10. Re: Set DPI from AIR'S Capturing Image.
                            Mohit M Chavda Level 1

                            Hi,

                             

                            Thanks for your reply

                             

                            According to me :

                             

                            -----------------
                            I download demo version from http://nikkosart.com/nikkoImage/download.cfm link but when i click save to server button it gives me security violation error may be because of missing crossdomain.xml in server side.

                             


                            You are right that DPI is mostly concern for printing.
                            Here i am working in one album maker software and need to print user defined imaeg's on 72 to 300 dpi as per user request.

                             

                            Here you can compare image dpi conversation with photoshop.

                             

                            take one image 72 dpi ( 400x400 ) open it into photoshop and convert it to 300 dpi (400 x400)

                             

                            here you can see difference in size of images so converted 300 dpi is exact same quality or in dpi that you can capture with your 300 dpi's digital camera.

                             

                            you can also check with imageMagic library
                            -----------------

                             

                            As per my inforamtion in flex / air dpi is depends on flash player and flash player is depend on computer's max resolution so if your computer's resolutions is higher you can capture higer dpi images using flex/ air
                            But i don't know how photoshop is converted image dpi in exact same as and regard less computer's resolution.

                             


                            Thanks,
                            Mohit.

                            • 11. Re: Set DPI from AIR'S Capturing Image.
                              gabrieldavis321 Level 1

                              Thank you for taking the time to look at nikkoImage. 

                               

                              I am not sure yet what you are trying to do.  I took an image 96 dpi opened in photoshop and saved it at 300 dpi.  When I did that photoshop automatically increased the height and width approx 3 times... but the image size in KB stayed the same... in other words it is just a bigger picture with less resolution...  the underlying picture data is unchanged... now it is just more "spread out" ...perhaps you want to do the same thing?  if so set the output dpi as i suggested and set scaleX and scaleY  to be 3 times larger... or am i not understanding something?

                               

                               

                               

                               

                              Date: Fri, 4 Feb 2011 00:12:18 -0700

                              From: forums@adobe.com

                              To: gdavis321@hotmail.com

                              Subject: Set DPI from AIR'S Capturing Image.

                               

                              Hi,

                               

                              Thanks for your reply

                               

                              According to me :

                              >

                              • 12. Re: Set DPI from AIR'S Capturing Image.
                                gabrieldavis321 Level 1

                                By the way did you open up the fla and change the line of code below?  you need to point to YOUR upload script page

                                 

                                //the url of the server page to upload

                                initparams.uploadURL = "http://127.0.0.1:8500/upload.cfm"

                                initparams.uploadURL = "http://nikkosart.com/nikkoImage/upload.cfm"

                                 

                                But thank you very much because I realized that in the publish settings I had left my own path "c:\cfusion\wwwroot\" which of course wouldn't work if you did not have that path... I changed it to a relative path and everything should work now.

                                 

                                Please let me know what you are trying to do and if it is a good project that maybe we can write and sell to many people.

                                 

                                Gabriel

                                 

                                 

                                 

                                From: gdavis321@hotmail.com

                                To: clearspace-1475826815-909327-2-3445101@mail.forums.adobe.com

                                Subject: RE: Set DPI from AIR'S Capturing Image.

                                Date: Thu, 3 Feb 2011 14:16:01 +0000

                                 

                                 

                                 

                                 

                                Mohit,

                                 

                                The images appear the same size on the computer screen because they are a certain pixel high and wide... but when you print the 72 image it will be much larger than than the 300 dpi image ... DPI is only used by the printer to know how many dots per inch (more dots smaller better definition image).... it is not used by computer screens.

                                 

                                Can you please do me a favor... please download the evaluation version of http://nikkosArt.com/nikkoImage and let me know what you think.  Please tell me anything that can make it better.

                                 

                                By the way NikkoImage lets you control the output scale of your image... so you can have a web page where the image is 300px but you can have it output a 600 px image (in other words make the picture bigger as you increase the output DPI).

                                 

                                Thanks!

                                Gabriel

                                 

                                 

                                Date: Thu, 3 Feb 2011 00:11:41 -0700

                                From: forums@adobe.com

                                To: gdavis321@hotmail.com

                                Subject: Set DPI from AIR'S Capturing Image.

                                 

                                Hi,

                                 

                                Thanks for reply.

                                Your give good solutions and i test it.

                                Here ony the the image's parameter is set as given dpi but internally image's size is same so we only see from mouse over or on image property that image's DPI is like 300 (as per given in JPGEncoder). But in original bitmap is not change.

                                 

                                I compare on this way  72 dpi , 300 dpi , 500 dpi. all have same size and same bitmap only i see that image property is set as per given dpi.

                                 

                                is there any way to set dpi on  image's as magicimage library or photoshop is given ?

                                can we apply your solution in pngencoder ?

                                 

                                 

                                By the way your answer is also helpful to me to undersand jpgencoder structure.

                                 

                                Thanks once again.

                                 

                                Mohit

                                >

                                • 13. Re: Set DPI from AIR'S Capturing Image.
                                  Mohit M Chavda Level 1

                                  Hi,

                                   

                                  I am work in one software company and work in one of client of this company who have one album studio. So project is to create Customize Album here you can apply most of functionaliy like photoshop gives (on image hue ,saturation , color effect ,dropshadow etcc...as well as  create vector ractangle etc.. and manage by user). Use exists temlate or create your customise template and apply this template to your album page so all image's on album and look of album page is set according to template

                                   

                                  Also you can connect this application whith photoshop and use photoshop functionality but if you don't have photoshop then you can use air functionality to create album images for print right now two option gives adove one jpeg (using jpeg encoder) one png ( using png encoder) in both of this user can give manual width and dpi setting and get output image accoring to that ...... now start my problem in internal air sdk ( may be flash player) not give us way to set your capturing image bitmap's dpi more than or less than your screen resolution it takes constant resolution (i.e. in my machine is 96dpi everytime) so everytime in bitmap dpi is same so bitmap size is also same.

                                   

                                  But look in photoshop if i change dpi like 72 to 300 then i see change in bitmap in bitmap also set 300 dpi.

                                   

                                  Here my client use big printer for print so he need this much dpi conversation.

                                   

                                  This is my story if you feel that this project fuctionality and your input(or idea) make some new idea which is new and this type of product demand in market then i am happy to hear you.

                                   


                                  Thanks,
                                  Mohit.

                                  • 14. Re: Set DPI from AIR'S Capturing Image.
                                    studio ludens

                                    *** UPDATE ***


                                    I got it working! I was staring blindly at the DPI variable, missing the "xyunit" change you did (from 0 to 1). It works sweetly now, thank you very much. Let me know if you do a similar thing for PNG, BMP or TIFF! I will be looking into it as well, but I am not much good as a low-level programming.

                                     

                                    *** END OF UPDATE ***

                                     

                                    Hi Gabriel,

                                     

                                    I have been looking for more than a year for a way to change the DPI of JPEGs. I was very frustrated that Flash/Flex did not allow me to set this. I fully understand that it does not change the quality of the image, but unfortunately the users of my software do not always... This means having to answer a lot of questions and concerns. Recently I wrote an extensive blogpost about it to help our users understand what DPI really meant (http://repperpatterns.com/2011/08/about-dpi-digital-imaging-and-repper/).

                                     

                                    Anyhow, I have used your little trick in JPGEncoder. However, I find out that the XDensity & YDensity are set correctly in the metadata of the image, but Photoshop does not recognize this and still sees it as a 72 DPI image (as does my printer driver). I tested your online version (NikkoImage) and noticed that Photoshop does detect the DPI in that image.

                                     

                                    Do you have a suggestion what I may be doing wrong? It's clear that the correct setting (in this testcase 300 DPI) is getting through, but cannot be detected by Photoshop or printer drivers. What am I missing here?

                                     

                                    Thanks!

                                     

                                    p.s. I second the request for a similar solution for the PNGEncoder (and why not for a BMPEncoder and TiffEncoder as well) ;-)