The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 7 of 7

Thread: Display Bitmap in

  1. #1

    Display Bitmap in

    Hey guys, I've got the following code that can write an image to a form but I want to put the image in a container.

    How can i do this? Can't find any resources for it.

    code:

    Code:
    public partial class MainForm : Form
        {
            private Bitmap bmp;
            public MainForm()
            {
                InitializeComponent();
                ImageMaker imgmkr = new ImageMaker(@"C:\Users\alexgeek\Pictures\scraps\logo\contact.gif");
                this.bmp = imgmkr.bmp;
                this.Paint += new PaintEventHandler(MainForm_Paint);
            }
    
            void MainForm_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = e.Graphics;
                Rectangle r = new Rectangle(0, 0, this.bmp.Width, this.bmp.Height);
                g.DrawImage(bmp, r, r, GraphicsUnit.Pixel);
            }
        }
        class ImageMaker
        {
            public Bitmap bmp;
            public ImageMaker(Bitmap newbmp)
            {
                this.bmp = newbmp;
            }
            public ImageMaker(string file)
            {
                if (System.IO.File.Exists(file))
                    this.bmp = new Bitmap(file);
                else
                    MessageBox.Show(file + " doesn't exist"); 
            }
        }
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  2. #2
    Oh fixed it sorry ha.
    I made a panel and set the Paint event to the current one.

    Out of interest what sets off the Paint event? If I wanted to "paint" the image at a certain time how would I do that?
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  3. #3
    component.invalidate();

    (maximize from minimize will call it also).

    Join #kirupa | Click the under my Username | CL | Jeff

  4. #4
    Okay thanks.

    New problem.
    I've created an image with the following code.. the image get's created correctly as I saved it and its worked. But I can't get it to display in the container, I get nullreference error.
    This is my code:
    Code:
    public partial class MainForm : Form
        {
            private Bitmap bmp;
            public MainForm()
            {
                InitializeComponent();
                ImageMaker imgmkr = new ImageMaker();
                this.bmp = imgmkr.getImage();
            }
    
            void MainForm_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = e.Graphics;
                g.DrawImage(this.bmp, new Point(0,0)); // ERROR ON THIS LINE!!!!!
            }
        }
    
     class ImageMaker
        {
            private Bitmap bmp;
            private Graphics gfx;
            public ImageMaker()
            {
                this.bmp = new Bitmap(400, 250);
                this.gfx = Graphics.FromImage(bmp);
                this.gfx.Clear(Color.White);
                this.gfx.SmoothingMode = SmoothingMode.AntiAlias;
                this.drawLine();
            }
            private int paddingLeft = 20;
            private int paddingRight = 20;
            private int paddingBottom = 20;
            private int paddingTop = 20;
            private void drawLine()
            {
                Pen linepen = new Pen(Color.SteelBlue, 5);
                Point drawFrom = new Point(this.bmp.Height - this.paddingTop,
                    this.paddingLeft);
                Point drawTo = new Point(this.bmp.Height - (this.bmp.Height - this.paddingBottom),
                    this.bmp.Width - this.paddingRight);
                gfx.DrawLine(linepen, drawFrom, drawTo);
            }
            public Bitmap getImage()
            {
                this.bmp.Save(@"C:\Users\alexgeek\Pictures\scraps\img.jpg");
                this.bmp.Dispose();
                this.gfx.Dispose();
                return this.bmp;
            }
        }
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  5. #5
    put a break point at:

    this.bmp = imgmkr.getImage();

    and:

    g.DrawImage(this.bmp, new Point(0,0));

    step through to make sure they are being called in the right order and that they("this.bmp") contain the right values.

    Join #kirupa | Click the under my Username | CL | Jeff

  6. #6
    I don't understand the information it gives me :/
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  7. #7
    Got it, the dispose() functions were destroying the image
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012