1 Reply Latest reply on Aug 14, 2010 6:14 AM by jeffcg2

    MSSQL image file to <mx:Image>

    jeffcg2 Level 1

      I have been using this cfc function to pull the binary image field from the db then write it as a .jpg file. Then use the <mx:Image> to display the .jpg file.

       

      I'm wondering if there is a shortcut to just read the MSSQL image field directly into the <mx:Image> tag

       

       

      <cffunction

       

      name="getItem" access="remote" output="false" returntype="query">

       

      <cfargument name="id" default="" type="numeric" required="true" />

       

      <cfset var qry = "" />

       

      <cfquery name="qry" datasource="mydb">

       

      select barcode,

      picture1, picture2

       

      from tipmont

       

      where id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#">

       

      </cfquery>

       

      <cfif #isbinary(qry.picture1)#>

       

      <cfimage source="#qry.picture1#" destination="C:\inetpub\wwwroot\photos\#qry.barcode#_1.jpg" action="write" overwrite="yes">

       

      </cfif>

       

      <cfif #isbinary(qry.picture2)#>

       

      <cfimage source="#qry.picture2#" destination="C:\inetpub\wwwroot\photos\#qry.barcode#_2.jpg" action="write" overwrite="yes">

       

      </cfif>

       

      <cfreturn qry>

       

      </cffunction>

       

      ------------------------------------------------------------------------------------------ -------------------------

       

      <mx:Image

       

      id="imgPicture1" source="../photos/{customDatatype.barcode}_1.jpg" width="100%" height="100%" scaleContent="true" autoLoad="true"/>

       

       

       

       

       

        • 1. Re: MSSQL image file to <mx:Image>
          jeffcg2 Level 1

          I found that configuring the return type to picture:ByteArray it is a simply <mx:Image source="{item.picture}"/> to display the MSSQL image field.

           

          But now I have a new question. What is different between the Coldfusion <cfimage> tag and the <mx:Image> tag?

           

          I have been using been using one handheld to collect field data including images that have a very low resolution and get stored as binary fields in MSSQL. The .jpg file created with the <cfimage> tag is only about 10k.

           

          Recently I updated to a handheld that is capable of taking images that <cfimage> will create a .jpg of 1 meg. I'm keeping these camera resolution down to where the final .jpg is about 50k.

           

          The only difference in the process is the resolution of the image.

           

          But the <cfimage> tag will create a .jpg from the low resolution binary and the <mx:Image> tag will not..