Code Monkey home page Code Monkey logo

Comments (9)

SimonZhao888 avatar SimonZhao888 commented on August 27, 2024 2

Hi @merriemcgaw, @elachlan

After investigating, we found that these line doubles the translation of the image in the x- and y-axes.

using var wg = WindowsGraphics.FromGraphics(graphics, ApplyGraphicsProperties.Clipping);
IntPtr dc = wg.GetHdc();

image

On the main branch, this issue has been fixed by #10645.

from winforms.

elachlan avatar elachlan commented on August 27, 2024

@Olina-Zhang can your team please test this?

from winforms.

elachlan avatar elachlan commented on August 27, 2024

This is my result on main branch.
image

private void Form1_Paint(object sender, PaintEventArgs e)
{
    Rectangle bounds = new(0, 0, 64, 64);
    e.Graphics.TranslateTransform(64, 32);
    e.Graphics.DrawIcon(Icon, bounds);
    Rectangle rectangleBounds = new(4, 4, 56, 56);
    e.Graphics.FillRectangle(Brushes.Blue, rectangleBounds);
}

Here is the code that does the transform:

// Draws this image to a graphics object. The drawing command originates on the graphics
// object, but a graphics object generally has no idea how to render a given image. So,
// it passes the call to the actual image. This version stretches the image to the given
// dimensions and allows the user to specify a rectangle within the image to draw.
internal void Draw(Graphics graphics, Rectangle targetRect)
{
Rectangle copy = targetRect;
using Matrix transform = graphics.Transform;
PointF offset = transform.Offset;
copy.X += (int)offset.X;
copy.Y += (int)offset.Y;
using DeviceContextHdcScope hdc = new(graphics, ApplyGraphicsProperties.Clipping);
DrawIcon(hdc, Rectangle.Empty, copy, true);
}

If I comment out the transform I get:
image

from winforms.

MandiMan avatar MandiMan commented on August 27, 2024

@elachlan Verified this issue on ScratchProject of winforms repo, latest .NET 9.0.100-preview.7.24329.1 and .NET Framework, the test results are the same:
image
.NET 8.0 test result:
image

from winforms.

elachlan avatar elachlan commented on August 27, 2024

@MandiMan Is the top result from framework on .NET9 Preview?

from winforms.

MandiMan avatar MandiMan commented on August 27, 2024

@elachlan I used the project attached to the Issue description to verify it on the latest .NET 9.0.100-preview.7.24329.1 with the following result:
image
When I add Rectangle rectangleBounds = new(4, 4, 56, 56); , the test result is as follows:
image
Also, An existing issue on this topic, mentioned in the Issue description, was verified with different results on .NET 8.0 and the latest .NET 9.0.
.NET 8.0 still doesn't reproduce:
image
.NET 9.0 reproduces it again, but the result is different from the original issue, which was a downward offset, and is now an upward offset:
image

from winforms.

elachlan avatar elachlan commented on August 27, 2024

@SimonZhao888 how difficult is the fix for .NET8/6?

from winforms.

SimonZhao888 avatar SimonZhao888 commented on August 27, 2024

Hi @MandiMan,
And for the existing issue, I can't repo on the main branch
image

I found that the code in the case project has a manual offset that we need to change it manually, it should be 0.
image

from winforms.

SimonZhao888 avatar SimonZhao888 commented on August 27, 2024

und that the code in the case project has a manual offset that we need to change manually,

It's hard to assess, but judging from Jeremy's PR, there are a lot of changes made.

from winforms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.