Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gordon Saxby 1347 posts 1608 karma points
    Apr 10, 2012 @ 22:19
    Gordon Saxby
    0

    Get crop dimensions in UserControl

    How do I get the crop details (x, y, x2, y2) for a specific crop?

    I need to get these details in a C# UserControl. I'm sure that I am missing something obvious ....

  • Simon steed 359 posts 668 karma points
    Apr 10, 2012 @ 22:24
    Simon steed
    0

    Are you talking about image size or the crop on an existing image? Does this help?

     

    http://webcache.googleusercontent.com/search?q=cache:bfO2UeTnB34J:stackoverflow.com/questions/111345/getting-image-dimensions-without-reading-the-entire-file+&cd=1&hl=en&ct=clnk&gl=uk

    USed the cache version as the live version is offline atm

  • Gordon Saxby 1347 posts 1608 karma points
    Apr 10, 2012 @ 22:32
    Gordon Saxby
    0

    I need to get the crop details - the uQuery component allows you to retrieve the URL of a specific crop, but I need the dimensions, i.e .the x, y, x2 and y2 values.

    It's not specifically the "size" of the cropped image, but the location and extent of the crop (top left to bottom right)!

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Apr 11, 2012 @ 10:55
    Jeroen Breuer
    0

    Well the crop info is stored in xml. If you have the media xml with a cropper on it the media should look something like this:

    <Image id="1131" version="31f54d4e-19e0-43ea-966f-8ec58f952bf7" parentID="1130" level="2" writerID="0" nodeType="1128" template="0" sortOrder="1" createDate="2012-01-18T11:08:12" updateDate="2012-01-18T11:05:19" nodeName="Koala.jpg" urlName="koala.jpg" writerName="admin" nodeTypeAlias="Image" path="-1,1130,1131">
      <cropper>
        <crops date="2012-01-18T11:08:13">
          <crop name="homeAbout" x="0" y="0" x2="1024" y2="334" url="/media/1476/Koala_homeAbout.jpg" />
        </crops>
      </cropper>
      <umbracoFile>/media/1476/Koala.jpg</umbracoFile>
      <umbracoWidth>1024</umbracoWidth>
      <umbracoHeight>768</umbracoHeight>
      <umbracoBytes>780831</umbracoBytes>
      <umbracoExtension>jpg</umbracoExtension>
    </Image>

    You can than use LinqToXml to get the info you need.

    Jeroen

  • Gordon Saxby 1347 posts 1608 karma points
    Apr 11, 2012 @ 11:10
    Gordon Saxby
    0

    Hi Jeroen - yes, I knew the data was in the XML ... my problem was getting to it! I ended up with code like this:

    var test = new Media(media.Id);
    var crops = test.getProperty("imageCropper").Value.ToString();
    XmlNode cropArea = null;
    var xmlCrops = new XmlDocument();
    xmlCrops.LoadXml(crops); 

    Then, to get the specific "crop" details:

    cropArea = xmlCrops.SelectSingleNode("/crops/crop [@name='Text Box 1']");

    And finally, extract the dimensions:

     var x1 = Convert.ToInt32(cropArea.Attributes["x"].Value)

     

     There is more code than the above, there are 3 text box crops and I get all 4 corners (x, y, x2, y2) but that is the basics of what I have working now. I'm not necessarily sure it is the best way but it works!

     

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Apr 11, 2012 @ 11:15
    Jeroen Breuer
    0

    Something like that is probably the best way. I prefer LinqToXml because you can fetch the data with a LINQ query which could be shorter.

    Jeroen

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies