Codecrete.SwissQRBill.WindowsTest.EmfMetaInfo.GetFrame C# (CSharp) Method

GetFrame() public method

Gets the metafile frame in pixels.

The frame is the metafile size set by the author.

This member function is similar to Metafile.GetBounds().

public GetFrame ( ) : RectangleF
return RectangleF
        public RectangleF GetFrame()
        {
            float deviceDpiX = DeviceSizePixel.Width / (DeviceSizeMicrometer.Width / 25.4f / 1000f);
            float deviceDpiY = DeviceSizePixel.Height / (DeviceSizeMicrometer.Height / 25.4f / 1000f);
            float left = Frame.Left / (25.4f * 100) * deviceDpiX;
            float right = Frame.Right / (25.4f * 100) * deviceDpiX;
            float top = Frame.Top / (25.4f * 100) * deviceDpiY;
            float bottom = Frame.Bottom / (25.4f * 100) * deviceDpiY;

            return new RectangleF(left, top, right - left, bottom - top);
        }

Usage Example

Esempio n. 1
0
        public void ToByteArray_CorrectFrame()
        {
            Bill bill = SampleData.CreateExample4();

            bill.Format.OutputSize      = OutputSize.A4PortraitSheet;
            using MetafileCanvas canvas = new MetafileCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, "Helvetica, Arial, \"Liberation Sans\"");
            QRBill.Draw(bill, canvas);

            EmfMetaInfo metaInfo = new EmfMetaInfo(canvas.ToByteArray());

            Assert.Equal(257, metaInfo.NumRecords);

            var scale = metaInfo.Dpi / 25.4f;
            // Returns the frame in pixels
            var frame = metaInfo.GetFrame();

            Assert.Equal(0, frame.Left);
            Assert.Equal(0, frame.Top);
            int expectedWidth = (int)(QRBill.A4PortraitWidth * scale);

            Assert.InRange(frame.Right, expectedWidth - 2, expectedWidth + 2);
            int expectedHeight = (int)(QRBill.A4PortraitHeight * scale);

            Assert.InRange(frame.Bottom, expectedHeight - 2, expectedHeight + 2);
        }