How to anchor zoom point in ScrollViewer+Image?

I'm using the following XAML to allow the user to pan and zoom with an image:
<ScrollViewer x:Name="scrollViewer" HorizontalSnapPointsType="None" HorizontalScrollBarVisibility="Auto" VerticalSnapPointsType="None" ZoomSnapPointsType="None" IsHorizontalRailEnabled="False" IsVerticalRailEnabled="False" ManipulationMode="All" VerticalScrollBarVisibility="Auto" ManipulationDelta="ScrollViewer_ManipulationDelta_1" IsDoubleTapEnabled="False" IsRightTapEnabled="False" IsTapEnabled="False">
<Image x:Name="pannableImage" Source="{Binding FullSizedImage}" ManipulationMode="All" Loaded="pannableImage_Loaded" IsDoubleTapEnabled="False" IsHitTestVisible="False" IsHoldingEnabled="False" IsRightTapEnabled="False" IsTapEnabled="False" ScrollViewer.VerticalScrollBarVisibility="Disabled" LayoutUpdated="pannableImage_LayoutUpdated">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="Scale" />
<RotateTransform x:Name="Rotate" />
<TranslateTransform x:Name="Translate" />
</TransformGroup>
</Image.RenderTransform>
</Image>
</ScrollViewer>
What I want to be able to do is keep the starting point of the zoom in the same place on the screen as the user zooms in or out.
In order to do that, I need to know the coordinates in the image where the zoom is starting so that I can then:
Get the screen coordinates for the image coordinates before the new scale factor is applied.
Get the screen coordinates for the image coordinates after the new scale factor is applied.
Adjust the translate transform so that the position stays the same
My problem lies in getting the point that the user is starting the zoom and then translating that into the underlying coordinates in the image.
I've tried:
private void scrollViewer_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
Debug.WriteLine("scrollViewer_ManipulationStarted: position = {0},{1}", e.Position.X, e.Position.Y);
GeneralTransform gt = pannableImage.TransformToVisual(scrollViewer);
GeneralTransform gti = gt.Inverse;
Point pt = gti.TransformPoint(e.Position);
Debug.WriteLine("scrollViewer_ManipulationStarted: image pos = {0},{1}", pt.X, pt.Y);
but the "image pos" numbers aren't right. It doesn't seem to matter if I pass scrollViewer or null to TransformToVisual.
This is for a Windows Universal App so needs to work on both Windows 8.1 and Windows Phone 8.1.
Can someone please advise a solution?
Thanks.

Hi Herro
Thank you for suggesting that code sample. It certainly does support zooming in and out beneath the manipulation point.
However, I am struggling to modify my existing implementation to support that different approach. There are a few areas where I'm having trouble and it may be that I just don't fully understand how the transforms work.
When the image is loaded, I want to make sure that, initially at least, the image is scaled so that it fits onto the screen. I'm using various events to trigger that initialisation but the core of the code is this:
double visibleHeight = Window.Current.Bounds.Height; // scrollViewer.ViewportHeight; //
double visibleWidth = Window.Current.Bounds.Width; // scrollViewer.ViewportWidth; //
// Get the image dimensions, allowing for rotation. We can be certain about
// using the values of 0, 90, 180, 270 because the rotation is always done in
// multiples of 90.
double imageHeight, imageWidth;
if (Math.Abs(selectedObject.Rotation) == 180 || selectedObject.Rotation == 0)
imageHeight = ManipulateMe.ActualHeight;
imageWidth = ManipulateMe.ActualWidth;
else
imageWidth = ManipulateMe.ActualHeight;
imageHeight = ManipulateMe.ActualWidth;
// If the image is larger than a screen dimension, work out
// what factor we want to make that dimension fit.
double scaleX, scaleY;
if (imageWidth > visibleWidth)
scaleX = visibleWidth / imageWidth;
else
scaleX = 1.0;
if (imageHeight > visibleHeight)
scaleY = visibleHeight / imageHeight;
else
scaleY = 1.0;
// Pick the SMALLER of the scale factors so that we ensure both
// dimensions fit onto the screen. Smaller because the values
// should be less than 1, so the smaller the value, the more the
// image is going to be reduced in size.
double scale;
if (scaleX < scaleY)
scale = scaleX;
else
scale = scaleY;
// Don't allow scale to be MORE than 1, at least initially. User can zoom in later.
if (scale > 1.0)
scale = 1.0;
if (scale != 1.0)
_compositeTransform.TranslateX = 0.0;
double scaledHeight = imageHeight * scaleY;
_compositeTransform.TranslateY = -(visibleHeight - scaledHeight) / 2;
_compositeTransform.CenterX = ManipulateMe.ActualWidth / 2;
_compositeTransform.CenterY = ManipulateMe.ActualHeight / 2;
_compositeTransform.ScaleX = _compositeTransform.ScaleY = scale;
Rect imageRect = _compositeTransform.TransformBounds(new Rect(0.0, 0.0, ManipulateMe.ActualWidth, ManipulateMe.ActualHeight));
double visibleLeft = 0, visibleTop = 0;
// Need to ensure that the image is positioned top-left
if (imageRect.Left != visibleLeft)
_compositeTransform.TranslateX = visibleLeft - imageRect.Left;
if (imageRect.Top != visibleTop)
_compositeTransform.TranslateY = visibleTop - imageRect.Top;
Now, when the page loads and displays the image, the image is perfect - scaled and positioned just right. However, if I then try to move the image, it vanishes and debugging information shows that the coordinates of the image are all over the place.
I *suspect* that the problem is being caused by my code setting up these initial values. My problem is that I don't know when to reset them or to what values.
My next problem is to do with the panning. I want to ensure that the user doesn't lose the image, so I want to ensure that when the image is larger than the screen, the right hand edge of the image can be off to the right but cannot move more to the left
than the right hand edge of the screen. Similarly for the other three sides of the image. My code works but it causes "bounces" in that the image seems to move back away from the screen edge and then back again to where I had "locked"
the edge. Again, it may be because I need to reset a translation value but I just don't know when or what to.
Below is my modified version of the ManipulationDelta routine:
void ManipulateMe_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
if (forceManipulationsToEnd)
e.Complete();
return;
_previousTransform.Matrix = _transformGroup.Value;
Point center = _previousTransform.TransformPoint(new Point(e.Position.X, e.Position.Y));
_compositeTransform.CenterX = center.X;
_compositeTransform.CenterY = center.Y;
// Reset rotation when user moves image around
_compositeTransform.Rotation = 0;
_compositeTransform.ScaleX = _compositeTransform.ScaleY = e.Delta.Scale;
Rect imageRect = ManipulateMe.RenderTransform.TransformBounds(new Rect(0.0, 0.0, ManipulateMe.ActualWidth, ManipulateMe.ActualHeight));
Debug.WriteLine("LTRB: {0},{1},{2},{3}", imageRect.Left, imageRect.Top, imageRect.Right, imageRect.Bottom);
double visibleHeight = Window.Current.Bounds.Height; // scrollViewer.ViewportHeight; //
double visibleWidth = Window.Current.Bounds.Width; // scrollViewer.ViewportWidth; //
double visibleLeft = 0, visibleRight = visibleWidth, visibleTop = 0, visibleBottom = visibleHeight;
double xAdjustment = e.Delta.Translation.X;
double yAdjustment = e.Delta.Translation.Y;
// If the image is SMALLER than the screen, don't let the edges of the image go beyond the screen edges
// If the image is LARGER than the screen, make sure that the edges of the image are either all outside
// the screen edges or stuck to the screen edges.
if (imageRect.Width <= visibleWidth)
Debug.WriteLine("... image is narrower than the screen");
// Lock to the left hand side
if ((imageRect.Left + xAdjustment) != visibleLeft)
xAdjustment -= (imageRect.Left + xAdjustment - visibleLeft);
else
//Debug.WriteLine("... image is wider than the screen");
if ((imageRect.Right + xAdjustment) < visibleRight)
Debug.WriteLine("... stopping image from moving off the right edge");
Debug.WriteLine("... right before adjustment = {0}", imageRect.Right);
Debug.WriteLine("... adjustment is {0}", xAdjustment);
Debug.WriteLine("... so potential new right is {0}", imageRect.Right + xAdjustment);
xAdjustment = (visibleRight - imageRect.Right);
Debug.WriteLine("... new adjustment is {0}", xAdjustment);
Debug.WriteLine("... and new right is {0}", imageRect.Right + xAdjustment);
if ((imageRect.Left + xAdjustment) > visibleLeft)
Debug.WriteLine("... stopping image from moving off the left edge");
Debug.WriteLine("... left before adjustment = {0}", imageRect.Left);
Debug.WriteLine("... adjustment is {0}", xAdjustment);
Debug.WriteLine("... so potential new left is {0}", imageRect.Left + xAdjustment);
xAdjustment = (visibleLeft - imageRect.Left);
Debug.WriteLine("... new adjustment is {0}", xAdjustment);
Debug.WriteLine("... and new left is {0}", imageRect.Left + xAdjustment);
if (imageRect.Height <= visibleHeight)
Debug.WriteLine("... image is shorter than the screen");
// Lock to the top
if ((imageRect.Top + yAdjustment) != visibleTop)
yAdjustment -= (imageRect.Top + yAdjustment - visibleTop);
else
//Debug.WriteLine("... image is taller than the screen");
if ((imageRect.Bottom + yAdjustment) < visibleBottom)
Debug.WriteLine("... stopping image from moving off the bottom edge");
Debug.WriteLine("... bottom before adjustment = {0}", imageRect.Bottom);
Debug.WriteLine("... adjustment is {0}", yAdjustment);
Debug.WriteLine("... so potential new bottom is {0}", imageRect.Bottom + yAdjustment);
yAdjustment = (visibleBottom - imageRect.Bottom);
Debug.WriteLine("... new adjustment is {0}", yAdjustment);
Debug.WriteLine("... and new bottom is {0}", imageRect.Bottom + yAdjustment);
if ((imageRect.Top + yAdjustment) > visibleTop)
Debug.WriteLine("... stopping image from moving off the top edge");
Debug.WriteLine("... top before adjustment = {0}", imageRect.Top);
Debug.WriteLine("... adjustment is {0}", yAdjustment);
Debug.WriteLine("... so potential new top is {0}", imageRect.Top + yAdjustment);
yAdjustment = (visibleTop - imageRect.Top);
Debug.WriteLine("... new adjustment is {0}", yAdjustment);
Debug.WriteLine("... and new top is {0}", imageRect.Top + yAdjustment);
_compositeTransform.TranslateX = xAdjustment;
_compositeTransform.TranslateY = yAdjustment;
e.Handled = true;
Many thanks for any suggestions you can make.
Regards
Philip

Similar Messages

  • How to plot two points simultaneously on image?

    I want to plot two points simultaneously on an image. I tried using IMAQ overlay point and IMAQ Light meter for point. But when I try to plot two points using either of these two VIs, I find not even one point is plotted. How to resolve this?
    Solved!
    Go to Solution.

    intensity a écrit:
    I want to plot two points simultaneously on an image. I tried using IMAQ overlay point and IMAQ Light meter for point. But when I try to plot two points using either of these two VIs, I find not even one point is plotted. How to resolve this?If your image is zoomed out, the point size may be to small to allow a proper drawing of the point. Otherwise IMAQ overlay point works flawlessly...
    Message Edité par chilly charly le 01-31-2009 11:40 AM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Example_VI.png ‏223 KB

  • How I can work points to an image in Illustrator for Screen Printing?

    Hello, (I use Macromedia Freehand MX), I just recently download the trial illustrator, and my question is to know how to open points in Illustrator images for screen printing in freehand using the Halftone in Illustrator I've tried but is not the same as the finish is different and of very poor quality here is a sample as freehand and illustrator as stated in:
    Look at the difference of points:
    As you can see in Illustrator can only do that from the menu: Effects / Pixelate / Color Halftone... and you can not make the points more guys, not sharp as seen in the picture above and therefore the image does not get to see very well, while in freehand if you can manipulate the points from large fine to a point, points also can be made round, linear or ellipse and therefore may work better for screenprints and other designs that open nesecitan points at home.
    What I'm interested to know if there is another way to work so that the image is sharp with the open items as well as in freehand.
    No more I say goodbye to waiting for an answer, thanks

    I still do not achieve the required result in Freehand give me the points, as you may see in the picture above, I need is to manipulate fine points as well as this:
    illustrator and only managed this:
    illustrator and only managed this:
    As you can see the difference is very remarkable, the two images are worked in the same size.
    I switch to illustrator but if I can achieve that result does not help me much, since I work in screen printing and printing and need to play with points, after that I love the program has many more things freehand.
    PS: the freehand halftone used to make color separation images to full color with spots open in Illustrator is not like that.

  • How to retain zoom position of an image using Adobe Flash Builder?

    Hi,
      I have created an Adobe Flash Builder Mobile App. I placed an image in the Homeview. I allow the user to zoom out or zoom in the image using GestureZoom.
    The problem is each time the user zooms, it does not retain the previous position.
    For ex., If I have a map image, I zoom the Bangalore area. After the zoom, I don't see the Bangalore area in the visible portion of the device screen.
    Can anyone help me in this? I feel this is a very basic requirement of zoom but I am missing something really.
    I have seen few samples of this requirement in Adobe Flash which does not work for mobile apps.

    I don't understand what you mean, but to give you a sample file so you can see what I am talking about:
    link to fla file: http://dl.dropbox.com/u/48932382/Untitled-1.fla
    link to swf file: http://dl.dropbox.com/u/48932382/Untitled-1.swf
    As you can see in this file, I am turning the green page, but when you should be seeing behind the page, it's actually transparent and you end up seeing the page underneath it.
    Here is a picture of it: (if your wondering, the pages have the same text, it's just the color of the pages are different)

  • How do I get rid of the metadata hangin on my mouse arrow when I point on an image.

    How do I get rid of the metadata hanging on my mousearrow when I point on an image in aperture.
    I hope it is possible to uncheck this feature. It is rather disturbing and not needed all the time.
    I hope someone can help me out!
    Thanks

    And in case anyone is wondering, hitting the "T" key is the keyboard shortcut to turn this feature on and off.

  • How do I zoom in on my workspace while a small window tells you where you are in your image?

    I'm a new user to PSE9, and I know the common basics. Currently, I'm working on an image that I've scanned onto my computer, but it's very large. I have to zoom into specific areas to get the colour right, but how can I zoom in while knowing where I am in the picture?
    My teacher has taught us how to find a window that allows you to zoom in and zoom out. I don't have a screenshot of it, but the window is normally in the top right corner and it shows your image. You can zoom in/out on the window with the magnifying glass while your actually sized workspace zooms with the window.
    I know this was hard to explain, and it might be hard to understand, but this will help me a lot when I'm working on my drawings as I'm hoping to specialize in digital art.

    Thanks so much!!!

  • How to adjust the position of an image in a full screen slideshow

    Hi I'am using a full screen slideshow composition on my page and muse is not letting me adjust the position of the image to the top, middle or bottom of the frame under the fill option when the image is selected in the slideshow.
    I also find it very buggy when previewing the page in a browser, some time it re-sizes the image only larger but never scales down proportionately, only on rare occasions. Why does this happen? 
    Can someone please help ASAP I need to get this site done by tomorrow.
    Thanks,
    Gary

    Welcome to Apple Support Communities.
    The effect you're looking for is 'Scale'
    In Keynote '09, 5.1.1 select the graphic.
    Click Inspector in the tool bar, Build Inspector (3rd icon from the left), (Build In and Build Out are both set to None for this step) Effect, Action, and then Scale.
    It rescales ('zooms') the selected item (image) up or down from 0% to 200%
    Clicking on the More Options button at the bottom opens a drawer to the left, and gives you more control over how the build occurs, whether they happen automatically, timed, or when you click, and re-order build steps.
    At 200%, double the original size, resolution could be a problem. There is a workaround, because it also scales smaller, down to 0%. So I would scale the graphic down 'small' as the first step to fit at the bottom, (even hide it behind a background-colored box) as you scale it down, and then at the end, scale up to full size to fill the screen at 'normal' resolution.
    In the attached example, I use a 'scale' up to go from 100% to 130% on a map, and use arrows and a flashing line to point out the road where a specific business is located with 12 steps. Some elements in my slides have been intentionally obscured. For simplicity, I've eliminated showing any steps but the initial title and the scale.

  • How would an Apple fan keep unwanted images out of Photostream in IOS 8?

    So Apple decides that people don't need an uncluttered thumbnail view of all photos stored in their iPhone in IOS 8. And the UI geniuses also decide that the concept of cloud (aka "server side" in 90's terms) storage and local storage is just too much for the average iPhone user to grasp.
    The UI design choices that sprung from this mindset have reduced usability, efficiency, but more importantly the family friendly reputation that Apple trades on in nearly all of their marketing material.
    Finding images (particularly when you have thousands) in the Years/Collections/Moments(Maps too!) paradigm is ridiculously inefficient compared to a scrolling screen with rows upon rows of thumbnails touching each other in chronological order. Of course we can quibble about whether the chronology should be based on file creation dates or EXIF metadata but those are decisions that we don't get in the IOS world (yes, another complaint). My main point here is that they had no reason to get rid of Camera Roll. Why can't it exist alongside the YCMM world of dates/locations and useless search tools? Let's face it, the new Recently Added Album is just a silly smart folder as are all the other albums. Why can't I change the 30 day date range to one of my choosing? Or why can't I add what Apple would call a Smart Album into my Albums just as I can add Cro-Mag dumb albums that need constant updating? This would bring back that good old Camera Roll functionality so people not confused by cloud vs local and like to keep track of their original image files could be happy. And the people that need Simple would be happy too.
    But back to my original query. I use my iPhone for many purposes including work. I also take iPhone screenshots for work. I also take a lot of pictures and not all of those images should be in my family and sharing oriented personal Photostream. After all Apple, you sold me an Apple TV which I can fire up and share my recent life experiences with others. Why the heck would I want product photography, conference room whiteboard pics, iPhone wallpaper, and all the different images that are not the "selects" but that I want to archive using Lightroom or iPhoto anyway showing up IN MY FAMILY SLIDESHOWS? One of the benefits of digital imaging is the cheap cost of creating and storing many images. I use my iPhone often as I would a DSLR and I frequently shoot many images that are very similar, sometimes using burst mode in the phone. Why would you force me to completely delete images that are not "favorites/selects" just so I can maintain a decent slideshow via Photostream? Why do you not want me to have pleasing wallpaper downloaded via the sundry App Store wallpaper apps? Any new wallpaper I add will now be in the Photostream. Yes, family dinner with the Apple TV slideshow showing images of cars, puppies, clouds, and abstract patterns interspersed with the trip to the pool last weekend sure makes for some great viewing!
    This is because you also killed the Photostream album view and I can no longer delete unwanted Photostream images unless I also want to completely delete the image local to the iPhone. If you go to the YCMM (Years/Collections/Moments/Maps) Photo tab there is no way to treat the local image separately from the cloud based Photostream image. This is absurd. You can't pitch Photostream as a lifestyle feature since you now prevent editing and curating this very audience specific collection of images. It's as if you forgot that a huge number of iPhone users are creative professionals! And we use our iPhones for professional purposes as well as personal.
    Not to mention that this design choice HUGELY increases the probability of "inappropriate" photos being uploaded to the cloud and lost control over through hacking or just user misunderstanding of how iCloud and Photostream works. Amazing that Apple would do this considering the recent scandal.
    So now I'll answer my own original question with a lame "workaround" answer. And yes, it involves a lot more work as opposed to the couple of touches that I used frequently in IOS 7 and earlier to curate my Photostream right on my iPhone: You have to have another IOS device (pre IOS 8) and delete the images from Photostream from there. Or use iPhoto to do the same. So add yet another task to your Reminders app that is now much more of a hassle.
    Apple, for the love of Pete, please don't take away control over my source image files and my ability to create collections of images for different purposes.
    Thanks.

    Excellently well put and accurate. The answer of course is that Apple want us to rent vast lumps of storage from them. Your point about appropriate images is well made. It's not just **** either but maybe legitimate images that you don't want shared out in the world, such as your wife and daughters caught on camera whilst sunbathing topless in the security of a private villa on holiday. That could prove embarrassing to them if they found their way out into the public domain, easily done by accident from a phone. The fact is that Apple have decided for pure commercial gain to take control of our means of controlling and storing our images. I shoot mainly portraits of my extended family and Landscapes. I don't want to share my images across mobiles etc, I want to sell them or give them to family members myself . Apple you are losing the plot here and alienating your core supporters.

  • How can you find out an individual image size from multiple images on a canvas

    This is probably a really really simple question but I can't for the life of me find how I can find out an individual image size from multiple images on a canvas. eg I have 3 photos i want to arrange 1 large and the other two next to it half the size. How can I edit individual image size on the canvas as when I select the image on a sperate layer I want to resize it just resizes the entire canvas and not the individual image
    Thanks

    I want to know they exact dimensions though. You can get them by dragging to the 0,0 corner and then reading off of the ruler scale on the sides but its fiddily as you have to zoom right in and work it out. I know in photoshop there is a ruler but is there any other way in Elements?

  • How to change the size of the image view

    I recently upgraded to CS5.1 from CS3. In CS3 there was an icon in the panel on the right side of the screen (I don't know the name of those panels) that had the option of zooming in on the image, and another icon for zooming out.
    I can't find this capability in CS5... Could someone please tell me how to activate it?
    Thanks!

    Edit
    Are you talking about Window > Navigator?
    Other than that zooming with command-space-click-and-drag and the keyboard shortcuts are options.

  • Zoom into high resolution image

    Hi,
    Before starting to learn Muse, I've one big need: zooming into high-resolution images.
    I want to show how high the resolution is by letting the viewer zoom in with a loupe (or just scrolling with mouse wheel). I'm not talking about of a slideshow through some crops of the main image, but of an shrink- or grow effect of the image.
    Is this possible to achieve?
    Thanks for your insight,
    Dominique

    Could this be the solution, you are looking for?
    https://creative.adobe.com/addons/products/2406#.U8Jp1mIaySM

  • HT5517 How can have full picture using mirrored image from iPad

    How can have full picture using mirrored image from iPad on my Apple TV airplay

    Welcome to the Apple Community.
    Mirroring won't fill the TV screen. The iPad has an aspect ratio of 4:3 and the iPhone 4S or prior an aspect ratio of 3:2, neither of these will fit exactly into a TV screen which as an aspect ratio of 16:9. The Apple TV will not zoom the mirrored image, because it may well cut off information which is situated at the top or bottom of the screen.
    You may wish to try each of the settings in ‘Settings > Audio & Video > Adjust for AirPlay overscan’ for the best setting that suits you.

  • When I print a webpage from FF how can I make the text and images bigger?

    I am trying to print an eticket for a flight. The text on the schedule comes out too small and the UPC symbol's black lines look ganged together. I know I can view it zoomed up, but how do I make the text and images stay zoomed so they will print out that way?

    I upgraded but the problem remains. At least with Firefox I do have the option to print a selection even if it mangles the top and bottom lines. With Safari or Chrome I have no option to print a selection. At the moment the only way to get a complete copy of the selection is to copy to openoffice etc and print from there.

  • HI Please Help me with Zoom of a buffered image

    Hi All,
    Please help,
    I want to zoom the buffered image using Affine Transforms, the code shown below can rotate the buffered image now how to zoom the same buffered image using Affine Transforms.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    public class RotationBounds extends JPanel implements ActionListener
        BufferedImage image;
        AffineTransform at = new AffineTransform();
        Rectangle2D.Double bounds = new Rectangle2D.Double();
        double theta = 0;
        double thetaInc = Math.PI / 2;
        public void actionPerformed(ActionEvent e)
            theta += thetaInc;
            setTransform();
            repaint();
        private void setTransform()
            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;
            double x = (getWidth() - iw) / 2;
            double y = (getHeight() - ih) / 2;
            at.setToTranslation(x, y);
            at.rotate(theta, iw / 2.0, ih / 2.0);
            x = (getWidth() - width) / 2;
            y = (getHeight() - height) / 2;
            // Set bounding rectangle that will frame the image rotated
            // with this transform. Use this width and height to make a
            // new BuffferedImage that will hold this rotated image.
            // AffineTransformOp doesn't have this size information in
            // the translation/rotation transform it receives.
            bounds.setFrame(x - 1, y - 1, width + 1, height + 1);
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            setBackground(Color.gray);
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
            if (image == null)
                initImage();
            g2.drawRenderedImage(image, at);
            // g2.setPaint(Color.blue);
            g2.draw(bounds);
            g2.setPaint(Color.green.darker());
            g2.fill(new Ellipse2D.Double(getWidth() / 2 - 2,
                getHeight() / 2 - 2, 4, 4));
        private void initImage()
            int w = 360, h = 300;
            image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2 = image.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setPaint(new Color(220, 240, 240));
            g2.fillRect(0, 0, w, h);
            g2.setPaint(Color.red);
            g2.drawString("Text for test", 50, 50);
            g2.drawRect(0, 0, w - 1, h - 1);
            g2.dispose();
            g2.setTransform(at);
    //        setTransform();
        private JPanel getLast()
            JButton rotateButton = new JButton("Rotate");
            rotateButton.addActionListener(this);
             JButton zoomButton = new JButton("Zoom");
            JPanel panel = new JPanel();
            panel.add(rotateButton);
            panel.add(zoomButton);
            return panel;
        public static void main(String[] args)
            RotationBounds test = new RotationBounds();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test);
            f.getContentPane().add(test.getLast(), "North");
            f.setSize(400, 400);
            f.setLocation(0, 0);
            f.setVisible(true);
    }Message was edited by:
    New_to_Java

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.util.Hashtable;
    import javax.swing.*;
    import javax.swing.event.*;
    public class RotationZoom extends JPanel {
        AffineTransform at = new AffineTransform();
        Point2D.Double imageLoc = new Point2D.Double(100.0, 50.0);
        Rectangle2D.Double bounds = new Rectangle2D.Double();
        BufferedImage image;
        double theta = 0;
        double scale = 1.0;
        final int PAD = 20;
        public RotationZoom() {
            initImage();
        public void addNotify() {
            super.addNotify();
            setTransform();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            g2.drawRenderedImage(image, at);
            g2.setPaint(Color.red);
            g2.draw(bounds);
        public Dimension getPreferredSize() {
            return new Dimension((int)(imageLoc.x + Math.ceil(bounds.width))  + PAD,
                                 (int)(imageLoc.y + Math.ceil(bounds.height)) + PAD);
        private void update() {
            setTransform();
            revalidate();
            repaint();
        private void setTransform() {
            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;
            at.setToTranslation(imageLoc.x, imageLoc.y);
            at.rotate(theta, scale*iw/2.0, scale*ih/2.0);
            at.scale(scale, scale);
            double x = imageLoc.x - scale*(width - iw)/2.0;
            double y = imageLoc.y - scale*(height - ih)/2.0;
            bounds.setFrame(x, y, scale*width, scale*height);
        private void initImage() {
            int w = 240, h = 180;
            int type = BufferedImage.TYPE_INT_RGB;
            image = new BufferedImage(w,h,type);
            Graphics2D g2 = image.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setBackground(new Color(220,220,240));
            g2.clearRect(0,0,w,h);
            g2.setPaint(Color.red);
            g2.draw(new CubicCurve2D.Double(0, h, w*4/3.0, h/4.0,
                                            -w/3.0, h/4.0, w, h));
            g2.setPaint(Color.green.darker());
            g2.draw(new Rectangle2D.Double(w/3.0, h/3.0, w/3.0, h/3.0));
            g2.dispose();
        private JPanel getControls() {
            JSlider rotateSlider = new JSlider(-180, 180, 0);
            rotateSlider.setMajorTickSpacing(30);
            rotateSlider.setMinorTickSpacing(10);
            rotateSlider.setPaintTicks(true);
            rotateSlider.setPaintLabels(true);
            rotateSlider.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    int value = ((JSlider)e.getSource()).getValue();
                    theta = Math.toRadians(value);
                    update();
            rotateSlider.setBorder(BorderFactory.createTitledBorder("theta"));
            int min = 50, max = 200, inc = 25;
            JSlider zoomSlider = new JSlider(min, max, 100);
            zoomSlider.setMajorTickSpacing(inc);
            zoomSlider.setMinorTickSpacing(5);
            zoomSlider.setPaintTicks(true);
            zoomSlider.setLabelTable(getLabelTable(min, max, inc));
            zoomSlider.setPaintLabels(true);
            zoomSlider.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    int value = ((JSlider)e.getSource()).getValue();
                    scale = value/100.0;
                    update();
            zoomSlider.setBorder(BorderFactory.createTitledBorder("scale"));
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            panel.add(rotateSlider, gbc);
            panel.add(zoomSlider, gbc);
            return panel;
        private Hashtable getLabelTable(int min, int max, int inc) {
            Hashtable<Integer,JComponent> table = new Hashtable<Integer,JComponent>();
            for(int j = min; j <= max; j += inc) {
                JLabel label = new JLabel(String.format("%.2f", j/100.0));
                table.put(new Integer(j), label);
            return table;
        public static void main(String[] args) {
            RotationZoom test = new RotationZoom();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(test));
            f.getContentPane().add(test.getControls(), "Last");
            f.setSize(500,500);
            f.setLocation(200,100);
            f.setVisible(true);
    }

  • When i Place a PSD in Indesign it comes in at 200+% while the image frame is considerably smaller. How do i place so that the image and image frame match?

    When i Place a PSD in Indesign it comes in at 200+% while the image frame is considerably smaller. How do i place so that the image and image frame match?

    Peter,
    The screenshots tell you everything.
    The second one tells you how the image frame is automatically set up after a one-click place. It's the blue stroked rectangle with the eight control points at each corner and mid-way along the line. This image frame is generated at a proportionally correct height and width for the image it contains.
    Now, if you look at the third screenshot (click on it to see it at a larger size), you will see I've used the direct selection tool (white arrow) to click on the image within the image frame. This CLEARLY shows the image (within the image frame) is substantially larger than the frame generated to contain it. This is indicated by the yellow stroked rectangle with the eight control points at each corner and mid-way along the line.
    Notice that the blue and yellow rectangles are vastly different sizes.
    In InDesign CS5.5, when i clicked to place the image, the image would fit perfectly within its image frame. the blue and yellow rectangles would match.
    I had no need to go click on the proportional fill and centre buttons like i need to do now in CC.
    I have a keyboard shortcut to place. I can't do File > Place for the amount of images i need to place.
    So to reiterate: How do i place an image so that the image and image frame match?

Maybe you are looking for

  • Error message when importing songs

    Hi. I get an error message - unknown error occurred while converting ... Ox77686174 etc - when I try to import songs from CD to itunes. It might happen with one song or with a whole CD. Very frustrating!! Also some songs do not import properly, eg, o

  • TV OUT?  i need this feature.   help

    I reviewed the phone on youtube, showed it could do tv out, bought the phone, no tv out?    this was one of the main features i wanted.  how can i get this done?   Thanks - Ryan

  • Can't create a page group

    Hi: i'm having troubles with a portlet wich is supossed to have a "create page group" functionality, but it really doesn't have it. i've seen documentation on Oracle about a portlet called "page groups" which gives the possiblity to build page groups

  • Problem in LDAP Configuration

    Hello everyone, I have a portal with java stack and i can create users from portal. But i am facing the problem while seeing the users in LDAP. For that i did the following... system admin->sys configuration->UM Configuration->LDAP server ->... here

  • Save InD CS3 Print Presets

    I am running CS3 Premium under Win XPro. I have just received my upgrade to CS4. Do I need to do anything special to save my print presets in InDesign CS3 for use with CS4 before I install?