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. C#
  4. Graphics.DrawImage half pixel clip and shift?

Graphics.DrawImage half pixel clip and shift?

Scheduled Pinned Locked Moved C#
graphicshelpcomquestion
3 Posts 2 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.
  • V Offline
    V Offline
    vineas
    wrote on last edited by
    #1

    I'm having a problem with a graphics control I'm working on. It seems that the Graphics.DrawImage method is clipping a half pixel off of the image, and then shifting it up and left by that half pixel. This can usually only be seen when zoomed in 2-4x or more, but now that I know what to look for, I'm seeing it happen even close to 1x with certain images. The following image shows the extent of the issue when zoomed in significantly - the green lines you see are where the bounds of the bitmap should be: odd_image.jpg[^] The graphics object that gets drawn to is from a bitmap that gets created on the fly depending on the size of the control and the objects in it. All graphics properties are set to the default except for the following: g.InterpolationMode = InterpolationMode.NearestNeighbor g.PageUnit = GraphicsUnit.Millimeter and there is a translation applied (though removing it did not affect the problem). I tried changing to the PageUnit to various values with no change, I also messed with PixelOffsetMode, CompositingMode, CompositingQuality and SmoothingMode, trying various values to no effect. I've done several searches in here and MSDN and found nothing that fixed the problem, or even hints that there is one. Has anyone seen anything similar to this, or have any ideas to try? ----- In the land of the blind, the one eyed man is king.

    J 1 Reply Last reply
    0
    • V vineas

      I'm having a problem with a graphics control I'm working on. It seems that the Graphics.DrawImage method is clipping a half pixel off of the image, and then shifting it up and left by that half pixel. This can usually only be seen when zoomed in 2-4x or more, but now that I know what to look for, I'm seeing it happen even close to 1x with certain images. The following image shows the extent of the issue when zoomed in significantly - the green lines you see are where the bounds of the bitmap should be: odd_image.jpg[^] The graphics object that gets drawn to is from a bitmap that gets created on the fly depending on the size of the control and the objects in it. All graphics properties are set to the default except for the following: g.InterpolationMode = InterpolationMode.NearestNeighbor g.PageUnit = GraphicsUnit.Millimeter and there is a translation applied (though removing it did not affect the problem). I tried changing to the PageUnit to various values with no change, I also messed with PixelOffsetMode, CompositingMode, CompositingQuality and SmoothingMode, trying various values to no effect. I've done several searches in here and MSDN and found nothing that fixed the problem, or even hints that there is one. Has anyone seen anything similar to this, or have any ideas to try? ----- In the land of the blind, the one eyed man is king.

      J Offline
      J Offline
      J Dunlap
      wrote on last edited by
      #2

      Setting the PixelOffsetMode to "HighQuality" worked for me before, IIRC.

      V 1 Reply Last reply
      0
      • J J Dunlap

        Setting the PixelOffsetMode to "HighQuality" worked for me before, IIRC.

        V Offline
        V Offline
        vineas
        wrote on last edited by
        #3

        That did it alright. I swore I tried that yesterday - but I tried a million combinations before giving up and posting, that one must have slipped through, or maybe it didn't work with some other setting I had at the time. Whatever, works now - Thanks! ----- In the land of the blind, the one eyed man is king.

        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