Drag Moouse to rotate Image Smoothly

I have to write an application look somewhat like igoogle's eyes. When I click onto an image, then every where I drag my mouse, the image will rotate smoothly (does not move, rotate only) to where my mouse position is? Think of an arrow that will rotate to point to wherever my pointer's position is. Can you guy give me some advices on how to accomplish this. Thanks. I do know the basic things, like how to rotate image and how to move object using MouseMotionListener... Thank in advance.
Edited by: yunaeyes on May 20, 2009 5:40 PM

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class SpinMe extends JPanel {
    BufferedImage image;
    double theta = 0;
    Point loc = new Point(140,150);
    public SpinMe() {
        initImage();
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        AffineTransform at =
            AffineTransform.getTranslateInstance(loc.x, loc.y);
        double cx = image.getWidth()/2.0;
        double cy = image.getHeight()/2.0;
        at.rotate(theta, cx, cy);
        g2.drawRenderedImage(image, at);
    private void initImage() {
        // make an image
        int w = 80;
        int h = 30;
        int type = BufferedImage.TYPE_INT_RGB;
        image = new BufferedImage(w, h, type);
        // make an arrow
        double cx = w/2.0;
        double cy = h/2.0;
        double len = w;
        double barb = 25.0;
        double phi = Math.toRadians(20);
        Path2D.Double arrow = new Path2D.Double();
        arrow.moveTo(cx-len/2, cy);
        arrow.lineTo(cx+len/2, cy);
        double theta = Math.PI + phi;
        double x = cx+len/2 + barb*Math.cos(theta);
        double y = cy + barb*Math.sin(theta);
        arrow.lineTo(x, y);
        arrow.moveTo(cx+len/2, cy);
        theta = Math.PI - phi;
        x = cx+len/2 + barb*Math.cos(theta);
        y = cy + barb*Math.sin(theta);
        arrow.lineTo(x, y);
        // draw the arrow into the image
        Graphics2D g2 = image.createGraphics();
        g2.setBackground(new Color(210,210,240));
        g2.clearRect(0,0,w,h);
        g2.setPaint(Color.red);
        g2.draw(arrow);
        g2.dispose();
    public static void main(String[] args) {
        SpinMe test = new SpinMe();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(test);
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
        test.addMouseListener(test.ma);
        test.addMouseMotionListener(test.ma);
    private double getTheta(Point p) {
        Point2D.Double ctr = getCenter();
        double dy = p.y - ctr.y;
        double dx = p.x - ctr.x;
        return Math.atan2(dy, dx);
    private Point2D.Double getCenter() {
        int iw = image.getWidth();
        int ih = image.getHeight();
        double cos = Math.abs(Math.cos(theta));
        double sin = Math.abs(Math.sin(theta));
        double width  = iw*cos + ih*sin;
        double height = ih*cos + iw*sin;
        Point2D.Double p = new Point2D.Double();
        p.x = loc.x + width/2;
        p.y = loc.y + height/2;
        return p;
    /** Use MouseInputAdapter for j2se 1.5- */
    private MouseAdapter ma = new MouseAdapter() {
        double offsetTheta;
        public void mousePressed(MouseEvent e) {
            offsetTheta = getTheta(e.getPoint()) - theta;
        public void mouseDragged(MouseEvent e) {
            theta = getTheta(e.getPoint()) - offsetTheta;
            repaint();
}

Similar Messages

  • 360 degree rotate image mouse drag edge tutorial

    360 degree rotate image mouse drag edge tutorial and give edge file

    My thoughts would be to, use an event listener for mouse
    down.. then depending on where the mouse is down have it create
    another event listener for mouse move, for example if the mouse x
    and y was in the range of where you want.. And after that in the
    mouse move function create a tween depending on where the mouse x
    or why moves to.
    private function mouseDOWN(evt:MouseEvent):void{
    //if mouse x or y is in the position rang wanted, create the
    event listener for mouse movement and mouse up.
    private function mouseMOVED(evt:MouseEvent):void{
    //if mouse y moved from original position, figure out the
    difference
    // create a tween on the object's original location, and
    addition of the difference.
    private function mouseUP(evt:MouseEvent):void{
    // remove all of the event listeners to stop all
    interaction. Also removing the mouse up listener.
    hope this helps

  • Problem with rotating images in Photoshop CC

    When I rotate images in Photoshop CC I get jagged edges and not smooth as before. What has changed? How can I sort this out? Is my software corrupted?  Still works perfectly in CS3.

    If your using Free Transform, then look at the Interpolation settings in the tool options bar
    Try one of the Bicubic settings
    (i have it set to Bicubic)
    For rotating the Canvas look at the Image Interpolation settings under Photoshop (Edit)>Preferences>General and use one of the Bicubic settings
    The standard Bicubic setting is a good all around setting

  • Rotating Image with Fade Effect

    Ok looking to rotate an image with a fade effect; below is a rotating image code.
    (Wanting this effect to be transitional and smooth. Transparency? Opacity?)
    <script language="JavaScript">
    <!--
    function adArray() {
    for (i=0; i*2<adArray.arguments.length; i++) {
    this[i] = new Object();
    this[i].src = adArray.arguments[i*2];
    this[i].href = adArray.arguments[i*2+1];
    this.length = i;
    function getAdNum() {
    dat = new Date();
    dat = (dat.getTime()+"").charAt(8);
    if (dat.length == 1)
    ad_num = dat%ads.length;
    else
    ad_num = 0;
    return ad_num;
    var ads = new adArray(
    "img1.jpg","http://www.domain.com",
    "img2.jpg","http://www.domain.com",
    "img3.jpg","http://www.domain.com");
    var ad_num = getAdNum();
    document.write('<div align="center"><A HREF="'+ads[ad_num].href+'" target="_blank"><IMG SRC="'+ads[ad_num].src+'" '
    +'BORDER=0 name=js_ad></A></div>');
    link_num = document.links.length-1;
    function rotateSponsor() {
    if (document.images) {
    ad_num = (ad_num+1)%ads.length;
    document.js_ad.src = ads[ad_num].src;
    document.links[link_num].href = ads[ad_num].href;
    setTimeout("rotateSponsor()",4000);
    setTimeout("rotateSponsor()",4000);
    // -->
    </script>
    Any ideas?

    Here is the script I finally got working! It would have not came to me without your help guys!
    <script>
    var pictureWebPartName="Pictures"; // name of the picture library web part
    var showThumbnails = true; //otherwise show full sized images
    var randomImg = true; //set to true to show in random order
    var useCustomLinks = false; //true to use second column as URL for picture clicks
    var RotatingPicturesLoopTime = 5000; //2000 = 2 seconds
    var imgToImgTransition = 1.0; //2 = 2 seconds
    // don't change these
    var selectedImg = 0;
    var imgCache = [];
    var imgTag;
    function RotatingPictures()
    imgTag = document.getElementById("RotatingImage");
    //Find the picture web part and hide it
    var Imgs = [];
    var x = document.getElementsByTagName("TD"); // find all of the table cells
    var LinkList;
    var i=0;
    for (i=0;i<x.length;i++)
    if (x[i].title == pictureWebPartName)
    // tables in tables in tables... ah SharePoint!
    LinkList = x[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
    // hide the links list web part
    LinkList.style.display="none";
    break;
    if (!LinkList)
    document.all("RotatingImageMsg").innerHTML="Web Part '" + pictureWebPartName + "' not found!";
    //Copy all of the links from the web part to our array
    var links = LinkList.getElementsByTagName("TR") // find all of the rows
    var url;
    var len;
    for (i=0;i<links.length;i++)
    //if (links(i).id.match("row")!=null)
    if (links[i].childNodes[0].className=="ms-vb2")
    len=Imgs.length
    Imgs[len]=[]
    Imgs[len][0] = links[i].childNodes[0].childNodes[0].href;
    if (useCustomLinks)
    if (links[i].childNodes[1].childNodes.length>0)
    { Imgs[len][1] = links[i].childNodes[1].childNodes[0].href; }
    else
    { Imgs[len][1] = "" }
    if (Imgs.length==0)
    document.all("RotatingImageMsg").innerHTML="No images found in web part '" + pictureWebPartName + "'!";
    for (i = 0; i < Imgs.length; i++)
    imgCache[i] = new Image();
    imgCache[i].src = Imgs[i][0];
    if (useCustomLinks)
    imgCache[i].customlink=Imgs[i][1];
    RotatingPicturesLoop();
    // now show the pictures...
    function RotatingPicturesLoop()
    if (randomImg)
    selectedImg=Math.floor(Math.random()*imgCache.length);
    if (document.all){
    imgTag.style.filter="blendTrans(duration=" + imgToImgTransition + ")";
    imgTag.filters.blendTrans.Apply();
    url=imgCache[selectedImg].src
    if (useCustomLinks)
    { RotatingImageLnk.href=imgCache[selectedImg].customlink; }
    else
    { RotatingImageLnk.href = url; }
    if (showThumbnails)
    // convert URLs to point to the thumbnails...
    // from airshow%20pictures/helicopter.jpg
    // to airshow%20pictures/_t/helicopter_jpg.jpg
    url = revString(url);
    c = url.indexOf(".");
    url = url.substring(0,c) + "_" + url.substring(c+1,url.length);
    c = url.indexOf("/");
    url = url.substring(0,c) + "/t_" + url.substring(c,url.length);
    url = revString(url) + ".jpg";
    imgTag.src = url;
    if (document.all){
    imgTag.filters.blendTrans.Play();
    selectedImg += 1;
    if (selectedImg > (imgCache.length-1)) selectedImg=0;
    setTimeout(RotatingPicturesLoop, RotatingPicturesLoopTime);
    // utility function revString found here:
    // http://www.java2s.com/Code/JavaScript/Language-Basics/PlayingwithStrings.htm
    function revString(str) {
    var retStr = "";
    for (i=str.length - 1 ; i > - 1 ; i--){
    retStr += str.substr(i,1);
    return retStr;
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("RotatingPictures");
    </script>
    <!-- add your own formatting here... -->
    <center>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td id="VU" height="125" width="160" align="center" valign="middle">
    <a name="RotatingImageLnk" id="RotatingImageLnk" alt="click for larger picture">
    <img src="/_layouts/images/dot.gif" name="RotatingImage" id="RotatingImage" border=0>
    </a>
    <span name="RotatingImageMsg" id="RotatingImageMsg"></span>
    </td>
    </tr>
    </table>
    </center>
    Thanks again guys!

  • Rotating images in Address Book??

    I am rather confused at the determination of Address Book to store contact photo's on one side??
    I have rotated images right round 360 degress but no matter what way up they are once I drag them on to the image frame, address book automatically rotates the image 90 degrees counterclockwise of the right way up???
    It is clever how it knows but also very frustrating? Does anybody else have this experience?
    Mac Mini connecting iPod Nano + Sony Ericsson K810i   Mac OS X (10.4.8)  

    Hi Wesley,
    Welcome to Apple Discussions
    Are you saying that Address Book takes an perfectly good upright image and rotates it 90 degrees CCW?
    I am a little confused by your statement.."It is clever how it knows but also very frustrating?"
    What program are you using to edit/rotate your images?
    Regards,
    John

  • My Rotated Images Do Not Save.

    I just processed my entire photography collection with Bridge. I rotated many of the photos. But now, as I'm looking at the folders in Windows Explorer, I notice that none of the images appear as being rotated.
    After reading the product support for rotating images in Bridge: "Rotating does not affect the image data; however, rotating an image in Adobe Bridge may rotate the image view in the native application as well."
    This is bad. Very bad. I do not want to go through ALL of my photos again and re-rotate them in another app. Is there any way for the rotations I made in Bridge to be saved to the image data?

    This is from Adobe:  Although Bridge allows you to quickly and easily rotate images, the rotation doesn't really happen until you open the file up in a graphics application such as Adobe Photoshop® or Adobe Illustrator® and save it in it's rotated state. So if you rotated an image in Bridge and then dragged it into Adobe InDesign®, it would appear with its original orientation.
    So with the above in mind seems like you can use the Image Processor in Bridge to open images in PhotoShop then save it.  It should be then rotated.    Since you are not adding anything the non-rotated images would remain unrotated so you don't have to know which ones were rotated and which ones were not.
    Or am I out to lunch?

  • Rotated Images? WHAT THE FRACK?!

    I don't understand this. Whenever I take an image, and place it on the desktop (Drag/Drop, or from Safari 'Save to Desktop'), it disappears off the desktop, and a folder is created called 'Rotated Images', and it's rotated. Even if I make it rotated back the way it's supposed to be through Preview, once it's back on the desktop, it auto rotates back and goes into the newly automatically created folder..
    How do I disable this feature?

    Try this in another browser and see if this still happening.
    Firefox http://www.mozilla.com/en-US/
    Photoscene
    PowerBook G4 17 inch, PowerBook G4 12 inch   Mac OS X (10.4.7)   Tiger/Panther

  • How to rotate image of picture ring

    Hi,
      I want to rotate image of picture ring (in particular angle). In my application I want to move a object(in circular form). Please tell me how to do it?
                                            - Thank you

    Hi,       I'm attaching one Jpg file; I need to move the train as per image route. I have tried position property node to change its position but problem is at turn, I can not rotate image of train smoothly through 900.                              - Thank you 
    Attachments:
    train.jpg ‏395 KB

  • Rotated image overlaps other controls

    Hi, I am working on an AIR app involving images. One of the functionalities is viewing as well as rotating images. I made a simple test app to illustrate this portion:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
        <mx:Script>
            <![CDATA[
                private function rotate():void
                    var bitmap:Bitmap = Bitmap(img.content);
                    var matrix:Matrix = bitmap.transform.matrix;
                    var centerX:Number = bitmap.width/2;
                    var centerY:Number = bitmap.height/2;
                    matrix.translate(-centerX, -centerY);
                    matrix.rotate(90*Math.PI/180);
                    matrix.translate(centerY, centerX);
                    bitmap.transform.matrix = matrix;
            ]]>
        </mx:Script>
        <mx:Text width="100%" text="Some text"/>
        <mx:Image id="img" width="100%" height="100%" source="test.jpg" horizontalAlign="center" verticalAlign="middle"/>
        <mx:Button label="rotate 90" click="rotate()"/>
    </mx:WindowedApplication>
    The application window has text on the top and a button on the bottom, with the image in the middle. Each click of the button rotates the image by 90 degrees.
    On launch, the app works great. It fetches the image file and fits it to the Image container. As I resize the application, the image also resizes and maintains the position relative to the other controls. Top text and bottom button are where they should be. All good. Let's assume the image is landscape/wide. After I perform the rotate 90 degrees by clicking the button, although the image is rotated and now in portrait orientation, the bottom portion of the image is now out of the image boundary and overlapping the button.
    Is there a way to tell the image to fit the content to the container again? Basically, re-layout the whole thing as if the image is in this new orientation.
    I suppose I can try to figure out a change in scale and resize the image, but I am not sure if this will hold when the user resizes the application. Also, the rotated image is now rather far to the left, as the "top left" corner is where a landscape image would be. For a portait orientation that's centered horizontally, it should be further to the right. I suppose I can also come up with some formula to center the rotated image. It just seems that the application already has all this logic built in, as it did exactly what I wanted when the image was loaded initially. If I can just ask the application to do it again. Note that similar issue occurs if the image starts out in portrait orientation and is rotated to landscape (too far to the right).
    Thanks in advance for the help.
    Will

    Thanks Sheila and Arnis,
    Today I opened the project to try different zoom settings and the problem has vanished; I get the correct arrow at zooms of 100, 120 and 140%.
    Likely a bug somewhere deep in Frame's innards. Anyway we've ordered TCS3 so soon I'll be using FM10. Thanks anyway.
    --- Derek

  • Is there a way to rotate images in iPhoto on the ipad

    I take photos with the iPhone or iPad and unless I sync them back to the Mac, there does not seem to be a way to rotate images. This makes having a nice slideshow (for the unlock screen) a problem as a bunch of images are all sideways. I'd like to be able to do simple edits like this in the device and not have to sync back and forth.

    You can't in the Photos app itself, though there are third-party apps that allow you e.g. PS Express (though the saved rotated version of the photo will be put in the Saved Photos album).

  • I have a Flash Sample to rotate images and text but I not find a way to display special characters

    Hello everyone.
    I bought a very nice Flash application that rotate images, and text of any color and size. It use an XML input file.
    I've posted here, a complete copy, so any of you can download, view and use it freely.
    I would appreciate if any of you know how to do, so that the text displayed, including the characters I use in my language (Spanish), such as á, é, í, ó, ú, ñ, and other special characters.
    In fact, I could not find a way to do it, because I'm not expert Flash, and less in ActionScript.
    If any of you would help me on that, I thank you implement the appropriate adjustments and compressed into a. zip file, and let me know where to download it, or if you prefer you can send it to my email: [email protected]
    After all compressed in .zip format is a very small file: 430K.
    Click here to download the complete sample.
    Thanks.
    =====================================
    Translated using http://translate.google.es
    =====================================

    Hello Rinus,
    If I understood your last post correctly, then problem 2 is resolved, right?
    Regarding problem 3:
    I'm not asking you to share exact VIs.
    I just want to see a very simple VI that explains the concept of what you're trying to do, what should happen (this can be in words that refer to the front panel elements) and what you've tried.
    The terminology you're using isn't clear to me without an extra explanation.
    This could even be only a Front Panel with a few buttons on where you just describe what should happen with specific controls/indicators.
    Based on the first post it is not clear to me what you mean with:
    - A "button element":
      Are you talking about a control, an indicator, a cluster that contains multiple control?
    - The structure:
      Is this an event structure, case structure, for loop, ...?
    Is it seems like you want to programmatically control Front Panel objects, which on itself is no problem at all independent of how many objects you want to control.
    Please share with me simple example of what goes wrong and explain which things should happen on that specific Front Panel.
    This will allow me to help you and also allow me to guide you along the right path.
    Kind Regards,
    Thierry C - Applications Engineering Specialist Northern European Region - National Instruments
    CLD, CTA
    If someone helped you, let them know. Mark as solved and/or give a kudo.

  • LR rotates images as they were at the upload

    Hi everybody
    I went back to a folder I haven't been looking for about 3-4 months. After I located the folder from the external disk all the images opened,  with my surprise, without the rotation I have set at the time so I had to to do it all again. Usually LR should retain the settings you apply to images, with no time limitation. So what happened in this case?
    p.s. it's even worse: LR is opening the images, in Grid View, initially with the rotation I set after the first opening but as I scroll down, always in Grid View, the images showed in the screen are rotated back as they were at the upload.
    Then I scroll down a bit more, images that were out of view are showed with the correct rotation and after a while they start rotating as they were at upload .....what the hell is going on???

    I think the key is when you said you have not viewed these pictures in 3-4 months. Therefore LR deleted its previews and the effect you are seeing is LR re-making them. If it does not have a preview in its cache it tries to be quick by showing you the JPG preview in the image file. That's as the camera recorded it. The it makes a preview from the image data, and finally applies the editing steps either from the catalog or the XMP information in the file.
    So if you give LR the time to do all that it should give you the pictures as you last had them in LR.
    I just went back to some pictures from February in my catalog and LR did recall the image orientations.
    BUT - I am also confused. I did a test and rotated a picture in LR. That rotation did not appear in the History panel. That surprised me, because LR does remember any rotations applied. I don't know where.
    Another factor may be that many cameras record the orientation in the EXIF. Thus my Canon DSLR rotates images correctly on the LCD display whereas my Nikon Coolpix P6000 does not. This could be part of your issue:- the camera's notion of orientation vs. LR's.
    So this is only a partial answer but I hope it helps.

  • When i drag and drop an image on my site. it gives the following error. "Unable to access local files due to browser security settings. To overcome this, follo"

    I am using the firefox version 17 and when i drag and drop an image on my website. It gives me the following error.
    Unable to access local files due to browser security settings. To overcome this, follow these steps: (1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again. Or go to the homepage for a link to the tutorial on how to do it.
    I have completed the above steps and it is still showing the same error message. Any help would be highly appreciated.
    Thanks.

    Thanks kumars ,
    I have a specific drag and drop area on our website. This works fine for all earlier releases of Firefox after these security settings
    "(1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again."
    Bust these settings not work for me in Firefox 17.
    Yes the drag and drop functionality is java script based and i am not using any script blocker addons.

  • I can't rotate images or text with two fingers on my trackpad.

    I have the most recent version of Keynote, using iOS 10.9.1 and a bluetooth trackpad.  Everything was working fine with the various gestures and now the rotation (two finger twisting) won't rotate images or text boxes.  Anybody else having this issue?  Any fixes you've seen that work?
    I've turned my bluetooth trackpad on/off.  I've checked my trackpad preferences checked/unchecked/checked.  Nothing seems to work.

    give gesture back please as soon as possible!!!

  • How to auto rotate Images on Full Screen Slideshow if pictures were taken mixed Portrait and Landsca

    In Muse: How to auto rotate Images on Full Screen Slideshow if pictures were taken mixed Portrait and Landscape

    There is no way that Muse would automatically rotate the images. What you can instruct Muse to do is whether you want to show all image content and leave blank space in either direction OR scale the image to fill the frame resulting in some cropping, but filling the otherwise blank space.
    The options are Fit Content Proportionally and Fill Frame Proportionally respectively.
    Cheers,
    Vikas

Maybe you are looking for