为什么使用Graphics.ScaleTransform(0.5f,0.5f)可以,而使用:float x = 图象.Image.Size.Width;
Graphics.ScaleTransform(x,x);
却不行?这样也不行:
float x = (float)图象.Image.Size.Width;
Graphics.ScaleTransform(x,x);这样更不行,运行中都停下来报错:
float x = (float)(600/图象.Image.Size.Width);
Graphics.ScaleTransform(x,x);分快没了,高手简单说说就行!

解决方案 »

  1.   

    Graphics.ScaleTransform(0.5f,0.5f)
    表示缩放后的宽是原来的0.5倍,长也是原来的0.5倍float x = (float)图象.Image.Size.Width;
    Graphics.ScaleTransform(x,x);
    缩放后的长,宽是原来的x倍,这样新得到的图片长宽太大,假设原来x是100,现在就是10000了,在内存中放不下这么大的图片自然就会报错了
      

  2.   

    还不行,代码如下:        private void 显示模板_Load(object sender, EventArgs e)
            {
                if (图象.Image.Size.Height > 600 || 图象.Image.Size.Width > 600)
                {
                    float x = (float)(600 / 图象.Image.Size.Width);
                    float y = (float)(600 / 图象.Image.Size.Height);
                    Image magnifyimage = new Bitmap(图象.Image.Size.Width, 图象.Image.Size.Height);
                    using (Graphics g = Graphics.FromImage(magnifyimage))
                    {
                        if (图象.Image.Size.Width > 图象.Image.Size.Height)
                        {
                            g.ScaleTransform(x, x);
                            //g.ScaleTransform(0.1f, 0.1f);
                        }
                        else
                        {
                            g.ScaleTransform(y, y);
                            //g.ScaleTransform(0.1f, 0.1f);
                        }
                        g.DrawImage(图象.Image, 0, 0);
                    }
                    图象.Image = magnifyimage;   
       
                }老报错,不知道什么原因.