Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Fixing an Image/Drawing so it doesn't auto-size

Fixing an Image/Drawing so it doesn't auto-size

Scheduled Pinned Locked Moved WPF
csharpwpfcomgraphicsadobe
4 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chaiguy1337
    wrote on last edited by
    #1

    I'm having this weird minor problem that I can't seem to figure out, probably because I don't understand enough of why it's happening. I have an ImageDrawing that I draw some shapes in, and then animate those shapes. Due to the animation, the size of the drawing changes, as do its edges relative to the "center" of the drawing, if you will, (or any fixed point in the drawing). What's happening is WPF is treating the image as an encapsulated object whose dimensions keep changing, resulting in it constantly "re-centering" itself, which results in my drawing moving around on the window when I want it to be completely fixed (so that the individual shapes animate, but the drawing as a whole stays in the same spot). Basically as far as I can tell is happening is the drawing is being "trimmed" (like in Photoshop), rather than staying a fixed size like a canvas. Any idea how to stop this happening? I've tried a few things like giving the Image a fixed width and height, but the drawing inside it still does the same trimming thing. Also I can't set HorizontalAlignment or VerticalAlignment because the top/bottom and left/right edges of the drawing still change (thanks again to the trimming).

    “Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’)            Built with home-grown CodeProject components! -”-”-

    C 1 Reply Last reply
    0
    • C chaiguy1337

      I'm having this weird minor problem that I can't seem to figure out, probably because I don't understand enough of why it's happening. I have an ImageDrawing that I draw some shapes in, and then animate those shapes. Due to the animation, the size of the drawing changes, as do its edges relative to the "center" of the drawing, if you will, (or any fixed point in the drawing). What's happening is WPF is treating the image as an encapsulated object whose dimensions keep changing, resulting in it constantly "re-centering" itself, which results in my drawing moving around on the window when I want it to be completely fixed (so that the individual shapes animate, but the drawing as a whole stays in the same spot). Basically as far as I can tell is happening is the drawing is being "trimmed" (like in Photoshop), rather than staying a fixed size like a canvas. Any idea how to stop this happening? I've tried a few things like giving the Image a fixed width and height, but the drawing inside it still does the same trimming thing. Also I can't set HorizontalAlignment or VerticalAlignment because the top/bottom and left/right edges of the drawing still change (thanks again to the trimming).

      “Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’)            Built with home-grown CodeProject components! -”-”-

      C Offline
      C Offline
      chaiguy1337
      wrote on last edited by
      #2

      I suppose I could put some invisible rectangle large enough to cover the area, but there must be a better way...

      “Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’)            Built with home-grown CodeProject components! -”-”-

      C 1 Reply Last reply
      0
      • C chaiguy1337

        I suppose I could put some invisible rectangle large enough to cover the area, but there must be a better way...

        “Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’)            Built with home-grown CodeProject components! -”-”-

        C Offline
        C Offline
        chaiguy1337
        wrote on last edited by
        #3

        Well I changed things around to use Line objects on a Canvas instead of LineGeometry's in an ImageDrawing and now I'm not having that problem. Not sure if I will incur a performance penalty doing it this way, but it seems a lot easier, and besides, it will allow me to do other things I was wanting to do (such as change opacity of individual pieces of the drawing) that I didn't realize weren't possible doing it the other way, so I think I'll stick with this. One more question for anyone who happens to be paying attention: It seems rather cumbersome to have to declare the stroke color, stroke thickness, start cap and end cap for every single Line object I create. It would be much handier if I could group these under some logical parent, and attach those properties once to the parent, and have them inherited by each child Line. In fact, I thought this was the whole point of attached properties, yet when I try to attach Shape.StrokeThickness (for example) to Canvas, I get an error that it can't find the attachable property. Is there some other way to achieve the same thing?

        “Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’)            Built with home-grown CodeProject components! -”-”-

        C 1 Reply Last reply
        0
        • C chaiguy1337

          Well I changed things around to use Line objects on a Canvas instead of LineGeometry's in an ImageDrawing and now I'm not having that problem. Not sure if I will incur a performance penalty doing it this way, but it seems a lot easier, and besides, it will allow me to do other things I was wanting to do (such as change opacity of individual pieces of the drawing) that I didn't realize weren't possible doing it the other way, so I think I'll stick with this. One more question for anyone who happens to be paying attention: It seems rather cumbersome to have to declare the stroke color, stroke thickness, start cap and end cap for every single Line object I create. It would be much handier if I could group these under some logical parent, and attach those properties once to the parent, and have them inherited by each child Line. In fact, I thought this was the whole point of attached properties, yet when I try to attach Shape.StrokeThickness (for example) to Canvas, I get an error that it can't find the attachable property. Is there some other way to achieve the same thing?

          “Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’)            Built with home-grown CodeProject components! -”-”-

          C Offline
          C Offline
          chaiguy1337
          wrote on last edited by
          #4

          Oh wait, duh, I know the answer to that: styles! :doh:

          “Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’)            Built with home-grown CodeProject components! -”-”-

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups