0
Bitmap OyunAlani = new Bitmap(400, 400);

private void Form1_Load(object sender, EventArgs e)
{
    backgroundWorker1.RunWorkerAsync();
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    ilerle();
}

void ilerle()
{
    while (true)
    {
        Size size = new Size();
        size.Width = 7;
        size.Height = 7;    
        Image i = (Image)OyunAlani;    
        pictureBox1.Image = ZoomPicture(i, size);
                
        System.Threading.Thread.Sleep(10);
    }
}

Image ZoomPicture(Image img, Size size)
{
    int genislik = Convert.ToInt32(img.Width * size.Width);
    int yukseklik = Convert.ToInt32(img.Height * size.Height);
            
    Bitmap bm = new Bitmap(img,genislik, yukseklik);                
            
    Graphics gpu = Graphics.FromImage(bm);
    gpu.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

    return bm;
}

My goal is to zoom a picture in a loop. I searched all topics about this problem but Dispose is not working. What should i do ? or alternative zoom solution?

Error is

System.ArgumentException 'parameter is not valid.'

Alexander Petrov
  • 13,457
  • 2
  • 20
  • 49
  • You are mixing several issues together. One is that your code throws error at some point `System.ArgumentException 'parameter is not valid.'` - You should check when and from which line is the error comming. You have possible wrong argument passing in the function. Second thing is the zoom problem & it depends how you want to solve it. But there should be clearly different question for that if so. – Tatranskymedved Dec 24 '20 at 11:09
  • Bitmap bm = new Bitmap(img,genislik, yukseklik); its error line – Sniper Sniperx Dec 24 '20 at 11:15
  • Why don't you put that info in the question? What are the values when the error is thrown? What values are acceptable by the function (e.g. is something of it null? Is something out of some range?)? – Tatranskymedved Dec 24 '20 at 11:18
  • Its work for 1 minute but Error thrown after 1 minute. – Sniper Sniperx Dec 24 '20 at 11:21
  • 1
    _or alternative zoom solution?_ -> [Zoom and translate an Image](https://stackoverflow.com/a/61964222/14171304). – dr.null Dec 24 '20 at 12:10

0 Answers0