method with Image return type or similar

Apr 30, 2013 at 7:48 AM
Edited Apr 30, 2013 at 8:11 AM
Is there any method that returns of type Image or something like that, so I can assign it to a picturebox ?

Because I tried with this:
protected override void OnPaint(PaintEventArgs e)
        {
            
            QrEncoder encoder = new QrEncoder(ErrorCorrectionLevel.M);
            QrCode qrCode;
            encoder.TryEncode("link to some website", out qrCode);

            new GraphicsRenderer(
                new FixedCodeSize(200, QuietZoneModules.Two)).Draw(e.Graphics, qrCode.Matrix);
            base.OnPaint(e);    
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.Invalidate();
        }
But didn't really work...
Apr 30, 2013 at 8:45 AM
I solved it:
public partial class Form1 : Form
    {
        public event PaintEventHandler Paint;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox_Paint);
            this.Controls.Add(pictureBox1);
        }

        private void pictureBox_Paint(object sender, PaintEventArgs e)
        {
            QrEncoder encoder = new QrEncoder(ErrorCorrectionLevel.M);
            QrCode qrCode;
            encoder.TryEncode("www.abix.dk", out qrCode);

            new GraphicsRenderer(
                new FixedCodeSize(200, QuietZoneModules.Two)).Draw(e.Graphics, qrCode.Matrix);
        }
    }