2 Replies Latest reply on Dec 18, 2014 8:56 AM by Flex harUI

    Flex image bitmap data crop when zoomed in/out

    rajbchaithanya

      I have an uploaded image cropped using flex handles,but I recently added the zoomIn/Out buttons so that uploaded big image can be zoomed out, the problem is : When zoomed out, am not able to fetch the crop handle Rectangle contents, Can some one please help out, am struggling since a day, I can share the whole code if some one can help..Thank you.


      <mx:UIComponent id="snapshotHolder" width="18" height="29" x="690" y="0"/>
        
      <example:SimpleFlexShape id="flexShape1" model="{flexModel1}" click="alignCropRectangle(2)"
        width
      ="0" height="0" y="0" x="0" enterFrame="alignCropRectangle(1)" />  
        
      <mx:UIComponent id="snapshotHolder" width="18" height="29" x="690" y="0"/>
        
      <example:SimpleFlexShape id="flexShape1" model="{flexModel1}" click="alignCropRectangle(2)"
        width
      ="0" height="0" y="0" x="0" enterFrame="alignCropRectangle(1)"/>


      var mat:Matrix = new Matrix();
        
      var rect:Rectangle = new Rectangle(0,0, flexModel1.width,flexModel1.height);
        
      //Moves the rectangle to the correct position to capture photo.
        mat
      .translate(-flexModel1.x, -flexModel1.y);  
        pic
      = new BitmapData(flexModel1.width, flexModel1.height, true);

        
      if(snapshotHolder.numChildren > 0)
        snapshotHolder
      .removeChildAt(0);

        pic
      .draw(uploadedImage.bitmapData,mat, new ColorTransform(),null,rect,true);

      private function alignCropRectangle(clickNbr:Number) : void {  
        
      //conditions that must be met so the box stays within the Uploaded Photo window
        
      if (ratio != 1.3) //Ratio should be 1:1.3
        ratio
      = 1.3;  
        flexModel1
      .height = flexModel1.width * ratio;
        
      if (flexModel1.x < 0)
        flexModel1
      .x = 0;
        
      if (flexModel1.y < 0 )
        flexModel1
      .y = 0;

        
      if(flexModel1.width > uploadedImage.sourceWidth) {
        
      //flexModel1.width = uploadedImage.sourceWidth - 30;
        flexModel1
      .height = flexModel1.width * ratio;
        
      } else if(flexModel1.width > 640) {
        
      //flexModel1.width = 640; //Doug Photo Crop issue
        flexModel1
      .height = flexModel1.width * ratio;
        
      }
        
      if(flexModel1.height > uploadedImage.sourceHeight) {
        
      //flexModel1.height = uploadedImage.sourceHeight - 30;
        flexModel1
      .width = flexModel1.height/ratio;
        
      } else if(flexModel1.height >= 480) {
        
      //flexModel1.height = 480; //Doug Photo Crop issue
        flexModel1
      .width = flexModel1.height/ratio;
        
      }


        
      /*When the user hold and drag the rectangle out of the display area
        the rectangle box comes backs to it's original position.*/

        
      if(clickNbr == 2) {
        
      if (flexModel1.x + flexModel1.width >= uploadedImage.sourceWidth)
        flexModel1
      .x = uploadedImage.sourceWidth - flexModel1.width;
        
      if (flexModel1.y + flexModel1.height >= uploadedImage.sourceHeight)
        flexModel1
      .y = uploadedImage.sourceHeight - flexModel1.height;
        
      }
        
      }