Hello

I need to stretch a bitmap image, i currently have a BMP file displaying in the form but it is only a few pixels big, i need to stretch the image to fit the form.

this is my current code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace attempt1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
          
        }

        
        private System.Drawing.Bitmap bitmap;







        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            

            Bitmap bitmap = new Bitmap("F:/Year3/Software Development/Assignment2/gameoflife/gameoflife/Bitmap1new.bmp");

            e.Graphics.DrawImage(bitmap, 10, 10);



    
        }


    }
}

any help would be great, thank you

try this:

private void ResizeImage()
        {
            //get the height and width of the image
            int width = this.Width;
            int height = this.Height;

            //create a new Bitmap the size of the new image
            Image img = Image.FromFile(@"F:/Year3/Software Development/Assignment2/gameoflife/gameoflife/Bitmap1new.bmp");
            Bitmap bmp = new Bitmap(width, height);
            //create a new graphic from the Bitmap
            Graphics graphic = Graphics.FromImage((Image)img);
            graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            //draw the newly resized image
            graphic.DrawImage(img, 0, 0, width, height);
            //dispose and free up the resources
            graphic.Dispose();
        }
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.