Professional Web Applications Themes

Image Cropping using Flex - Macromedia Flex General Discussion

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....

Sponsored Links
  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.
    Sponsored Links
    kalyanvarma Guest

  2. #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

  3. #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

  4. #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

Similar Threads

  1. flex 3 image
    By nandi_mrinal2005@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 1
    Last Post: February 23rd, 12:00 PM
  2. Dynamic Image in Flex
    By wild-west in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: December 2nd, 06:28 PM
  3. Image Cropping Utility
    By RRAM webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 2
    Last Post: January 23rd, 02:44 AM
  4. Cropping Image filters border
    By Nancy S in forum Adobe Photoshop Elements
    Replies: 2
    Last Post: August 13th, 06:25 PM
  5. Simple task: Cropping an image to an oval (ellipse)
    By Natalie Avalos in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 13
    Last Post: August 6th, 02:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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