IOS Xamarin - การวาดเส้นแบบเรียลไทม์

ฉันกำลังทำงานในโปรเจ็กต์ทดสอบข้ามเพื่อแสดงกราฟคลื่นไฟฟ้าหัวใจแบบเรียลไทม์ มันทำงานได้ดีบน windows และ android ที่ใช้ Xamarin แต่ใน IOS ฉันมีประสิทธิภาพที่ช้าและช้า

ฉันคิดว่าปัญหาเกิดจากการที่ฉันขาดความเชี่ยวชาญใน iOS

ฉันได้ทำการทดสอบสองครั้งแล้วทั้งสองล้มเหลว มีคนมีวิธีแก้ไขให้เร็วขึ้นหรือไม่

ทดสอบ ก

ฉันเรียก Plot แล้วกำหนด UIImage wBitmap เป็น MyView Backgroud ทุก ๆ ‹ 10ms

    public void Plot(PointF pPrec, PointF pNext)
    {
    SizeF bitmapSize = new SizeF(wBitmap.Size);
    using (CGBitmapContext context2 = new CGBitmapContext(IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst))
    {
        context2.DrawImage(new RectangleF(0, 0, wBitmap.Size.Width, wBitmap.Size.Height), wBitmap.CGImage);
        context2.SetLineWidth(1);
        context2.AddLineToPoint(pNext.X, pNext.Y);
        context2.DrawPath(CGPathDrawingMode.Stroke);
        // output the drawing to the view
        wBitmap = UIImage.FromImage(context2.ToImage());
    }
}

ทดสอบข

ฉันเรียก Plot แล้วกำหนด UIImage wBitmap เป็น MyView Backgroud ทุก ๆ ‹ 10ms

    public void Plot2(PointF pPrec, PointF pNext) { UIGraphics.BeginImageContext(wBitmap.Size); context = UIGraphics.GetCurrentContext();
    using (context)
    {
        if (wBitmap != null)
        {
            context.TranslateCTM(0f, wBitmap.Size.Height);
            context.ScaleCTM(1.0f, -1.0f);
            context.DrawImage(new RectangleF(0f, 0f, wBitmap.Size.Width, wBitmap.Size.Height), wBitmap.CGImage);
            context.ScaleCTM(1.0f, -1.0f);
            context.TranslateCTM(0f, -wBitmap.Size.Height);
        } 

        context.SetLineWidth(1);
        context.MoveTo(pPrec.X, pPrec.Y);
        context.AddLineToPoint(pNext.X, pNext.Y);
        context.DrawPath(CGPathDrawingMode.Stroke);

wBitmap = UIGraphics.GetImageFromCurrentImageContext();


    }//end using cont
    UIGraphics.EndImageContext();
}

person Andrea Falappi - Polipo    schedule 17.02.2014    source แหล่งที่มา
comment
ทำไมคุณต้องเรียกสิ่งนี้ทุกๆ 10 มิลลิวินาที? เหมือนจะเกินกำลังไป   -  person bbarnhart    schedule 17.02.2014
comment
ใช่ โปรแกรม ECG แบบเรียลไทม์ส่งตัวอย่างทุกๆ 2 มิลลิวินาที (พิกัด x,y) ฉันสามารถทิ้งตัวอย่าง 5 ตัวอย่างเพื่อทำลาย กระบวนการวาดจะสร้างจุดใหม่ทุกๆ 10 มิลลิวินาที บน Galaxy tab 3 Android และ Windows Samsung ATIV ทำงานได้อย่างสมบูรณ์แบบ   -  person Andrea Falappi - Polipo    schedule 17.02.2014


คำตอบ (1)


คุณไม่จำเป็นต้องวาดลงในบิตแมปก่อน แล้วจึงใช้บิตแมปนั้นในมุมมอง วิธีการที่ถูกต้องในการทำเช่นนี้คือการซับคลาส UIView จากนั้นแทนที่เมธอด Draw() และระบายสีเนื้อหาของคุณลงไป

จากนั้นคุณสามารถโทร SetNeedsDisplay() บนมุมมองเพื่อกำหนดเวลาการวาดใหม่

ตัวอย่างด้านล่างวาดพื้นหลังรูปลูกศร:

class YourView: UIView
{
public override void Draw(RectangleF rect)
{
    const float inset = 15f;
    UIColor.Blue.SetFill();
    var path = new UIBezierPath();
    path.MoveTo(new PointF(0, 0));
    path.AddLineTo(new PointF(rect.Width - inset, 0));
    path.AddLineTo(new PointF(rect.Width, rect.Height * 0.5f));
    path.AddLineTo(new PointF(rect.Width - inset, rect.Bottom));
    path.AddLineTo(new PointF(0, rect.Bottom));
    path.AddLineTo(new PointF(0, 0));
    path.Fill();
}
}
}

หรืออีกทางหนึ่ง คุณอาจต้องการดูส่วนประกอบที่มีอยู่ เช่น CorePlot หรือ TeeChart มีอยู่ในร้านค้า Xamarin Components TeeChart จะเป็นแพลตฟอร์มแบบข้ามแพลตฟอร์ม ดังนั้นคุณจึงไม่ต้องกังวลเกี่ยวกับ Android กับ iOS

person Krumelur    schedule 17.02.2014