Image Cropping using Flex

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default Image Cropping using Flex

    Hi All,

    Can anyone help me with an approach to do image cropping using Flex? It is really helpful if I can get it fast.

    Thanking you in advance.
    kalyanvarma Guest

  2. Similar Questions and Discussions

    1. flex 3 image
      hello, i am a new flex 3 user. i am working on image control. i want to change the saturation, hue and lightness of an image through flex code. Is...
    2. Dynamic Image in Flex
      How do I get this to work? <mx:Image id="myImage" source="@Embed('assets/{selectedItem.label}.jpg')" For some reason, {selectedItem.label} is...
    3. Image Cropping Utility
      I might be posting this in the wrong forum but here it goes. I'm trying to create a "cropping" box in flash where I would load a jpg dynamically...
    4. Cropping Image filters border
      Jason, That is most likely due to anti-aliasing. There is a checkbox on option bar to use it or not. However, if not used, the edges appear very...
    5. Simple task: Cropping an image to an oval (ellipse)
      Hello all, I've been using Photoshop 6.0 for Windows for about 5 years now, primarily for basic photo editing. However, now I am experimenting and...
  3. #2

    Default Re: Image Cropping using Flex

    You can either use image x/y and height/width to just show the portion of the image you desire, you can check into using the BitmapData.copyPixels method to copy a portion of one image into a new one.
    slaingod Guest

  4. #3

    Default Re: Image Cropping using Flex

    Hi Slaingod,

    Thanks for you reply. But the requirement here is the user should be able to
    select the area and get the image of the desired area he selects. So, how to
    get that select tool.

    Thanking you in advance.

    kalyanvarma Guest

  5. #4

    Default Re: Image Cropping using Flex

    You can use mouse events and anything that draws a rectangle (even Canvas or
    TextArea) and use the borders for your selection.

    I'm sure if you did a google for Flex selection rectangle there would be
    examples. Quasimod has an old AS2 one for 'marching ants' selection, that
    could be adapted.

    Here is some partial code that will get you going...may not contain everything
    you need, but certainly shows the important pieces...

    private var origin:Point = null;
    private var release:Point;
    private var lastMouseCoords:Point = new Point();

    public function onPicMouseDown(e:MouseEvent):void {
    pic_selection.addEventListener(MouseEvent.MOUSE_MO VE, onPicMouseMove);
    pic_selection.addEventListener(MouseEvent.MOUSE_UP , onPicMouseUp);
    pic_selection.addEventListener(MouseEvent.ROLL_OUT , onPicMouseOut);
    selection.visible = true;
    selection.width = 4;
    selection.height = 4;
    origin = new Point(pic_selection.x + e.localX, pic_selection.y + e.localY);
    selection.x = origin.x;
    selection.y = origin.y;
    }

    public function onPicMouseUp(e:MouseEvent):void {
    release = new Point(pic_selection.x + e.localX, pic_selection.y +
    e.localY);
    selectionDone();
    }

    private function selectionDone():void {
    pic_selection.removeEventListener(MouseEvent.MOUSE _MOVE,
    onPicMouseMove);
    pic_selection.removeEventListener(MouseEvent.MOUSE _UP, onPicMouseUp);
    pic_selection.removeEventListener(MouseEvent.ROLL_ OUT, onPicMouseOut);
    crop_instructions.visible = false;
    story.visible = true;
    if(Math.abs(origin.x - release.x) < 5 || Math.abs(origin.y - release.y) <
    5) {
    origin = null;
    release = null;
    selectionReset()
    }
    }

    public function onPicMouseOut(e:MouseEvent):void {
    release = new Point(lastMouseCoords.x, lastMouseCoords.y);
    selectionDone();
    }

    private function selectionReset():void {
    selection.x = 0;
    selection.y = 0;
    selection.height = 0;
    selection.width = 0;
    selection.visible = false;
    }

    public function onPicMouseMove(e:MouseEvent):void {
    lastMouseCoords.x = pic_selection.x + e.localX;
    lastMouseCoords.y = pic_selection.y + e.localY;

    // drag the selection rectangle
    selection.x = Math.min(pic_selection.x + e.localX, origin.x);
    selection.y = Math.min(pic_selection.y + e.localY, origin.y);

    // we could make it a square by setting height and width to minimum
    // but lets leave it for now... maybe someone wants to crop kids out
    selection.width = Math.abs(pic_selection.x + e.localX - origin.x);
    selection.height = Math.abs(pic_selection.y + e.localY - origin.y);
    }

    slaingod Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139