private void likeStretchBlt()
        {
           Bitmap temp = new Bitmap(CallDLL.width * zoomTime, CallDLL.height * zoomTime);  //zoomTime是放大倍数>=1的整数
            temp = pictureExtend(bmpRef);
            this.pictureBoxRef.Image = temp;    //窗体中的一个图片框
         
            Bitmap temp2 = new Bitmap(CallDLL.width * zoomTime, CallDLL.height * zoomTime);  //*******放大的时候,会报出ArgumentException            temp2 = pictureExtend(bmpDef);
            this.pictureBoxDef.Image = temp2;   //窗体中的另一个图片框
            
        }        private Bitmap pictureExtend(Bitmap bmp)
        {
            Bitmap temp = new Bitmap(bmp.Width * zoomTime, bmp.Height * zoomTime);               Graphics graph2 = Graphics.FromImage(temp);
            graph2.InterpolationMode = InterpolationMode.NearestNeighbor;
            //graph2.InterpolationMode = InterpolationMode.High;   //设置高质量插值法
            //graph.SmoothingMode = SmoothingMode.HighQuality;
            //graph2.CompositingQuality = CompositingQuality.HighQuality;  //高质量,低速度复合
            graph2.DrawImage(bmp, 0, 0, bmp.Width * zoomTime, bmp.Height * zoomTime); //后四个参数是源图片的参数
            graph2.Dispose();
            return temp;
        }对图片框中的两幅图片同时进行放大,点击放大的时候反应就很慢,在放大到某一倍数的时候就会报出ArgumentException,我觉得可能是图片太大的缘故,有2018*1536大小,我曾今也试过和VC中一样的StretchBlt()但是没反应出效果,可能是哪边用错了,我想问一下,报出这样的异常是不是因为用的这种C#内置的放大算法,图片太大,就会有错误?

解决方案 »

  1.   

     return image.GetThumbnailImage(999, 999, null, IntPtr.Zero);
      

  2.   

    DrawImage方法确实是慢,耗内存,反正C#内置的很多东西效率都很低,比如SetPixel。
    我现在用StretchBlt()确实放大反应很快,也没有报出这种异常,但是遇到一个问题:图片放大之后,只能显示图片框大小的区域图片,图片框下是放了一个panel的,用作图片框的父容器,它的AutoScroll属性设为true,图片框的AutoSizeMode设为true。以前用DrawImage方法,也没出现过这种情况,图片放大之后,panel会自动添加滚动条用于显示全图片。
      

  3.   

    代码如下:        private void pictureBoxRef_Paint(object sender, PaintEventArgs e)
            {
                graphRef = e.Graphics;            IntPtr hDC = graphRef.GetHdc();   //DC
                IntPtr hSrcDC = CreateCompatibleDC(hDC);     //DC            IntPtr hbmp = bmpRef.GetHbitmap();              //GDIObject
                IntPtr hOrig = SelectObject(hSrcDC, hbmp);      //Object              SetStretchBltMode(hDC, StretchMode.STRETCH_HALFTONE);
                StretchBlt(hDC, 0, 0, CallDLL.width * zoomTime, CallDLL.height * zoomTime, hSrcDC, 0, 0, CallDLL.width, CallDLL.height, TernaryRasterOperations.SRCCOPY);
                pictureBoxRef.SizeMode = PictureBoxSizeMode.AutoSize;            IntPtr hNew = SelectObject(hSrcDC, hOrig);            DeleteObject(hNew);
                DeleteDC(hSrcDC);
                graphRef.ReleaseHdc(hDC);
            }       private void numericUpDownZoom_ValueChanged(object sender, EventArgs e)
           {
                Refresh();
           }这问题不知怎么解决,如果是pictueBox和panel控件的属性设置错误,也不知道该怎么设,因为我已经试过很多了,只有这种设法才能有显示全图片,如果全图片大于图片框本身的大小,会有滚动条。我在网上查了很多,也没找到解决方法,如果谁知道的,告知一声,不胜感激!(为什么回答的人这么少啊~~~~~~)