Hello,

I have been using C++ for not so long and today I have find a problem that I know it is not difficult but I haven't done it before so I have no idea.

I have a matrix(System::Drawing::Drawing2D::Matrix^ L) and I want to apply this property OffsetX. since now I have worked with methods (L->method) but I have seen in the help that I should use get I I don't know how to make it.

Could anyone of you help me?
Thank you in advanced!

Dani AI

Generated

Brief follow-up to and : OffsetX/OffsetY are the matrix translation components but they are exposed as read-only properties. To change a matrix translation you must call matrix methods or build a new matrix rather than assign to OffsetX.

To add a translation (relative change) use Translate:

// add (dx,dy) to the existing transform
L->Translate(dx, dy, System::Drawing::Drawing2D::MatrixOrder::Append);

To set an absolute translation (replace the translation part) read the linear elements and construct a new Matrix with the same linear terms and new dx/dy:

array<float>^ e = L->Elements;  // {m11, m12, m21, m22, dx, dy}
float m11 = e[0], m12 = e[1], m21 = e[2], m22 = e[3];
auto m = gcnew System::Drawing::Drawing2D::Matrix(m11, m12, m21, m22, newDx, newDy);

Notes and pointers: Elements are returned in the order {m11, m12, m21, m22, dx, dy} and are useful when you need explicit access to the matrix components. Translate accepts a MatrixOrder (Append vs Prepend) which changes whether the translation is applied before or after the current transform. See the official docs for details on Elements and Translate for exact behavior and overloads (Matrix.Elements and Matrix.Translate).

Recommended Answers

All 2 Replies

OffsetX is a read-only property, so all you can do is get the value:

x = my_matrix->OffsetX;

ok!
I thought it didn't work the same way!!

Thank you so much for your help!!
I mark the thread as solved! ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.