我是这么用了,没有实现我所需的放大功能啊。我用的是一个按钮来实现的,具体如下:
 private void picBox_Click(object sender, EventArgs e)//该按钮要实现放大功能
        {
           
            Image imgPhotoVert = Image.FromFile(@"F:\风景图片\image1.jpg");//我的图片在F盘
            Image imgPhoto = null;
            imgPhoto = ScaleByPercent(imgPhotoVert, 50);
            imgPhoto.Save(@"F:\风景图片\image11.jpg", ImageFormat.Jpeg);//保存的F盘下
            imgPhoto.Dispose();
         }
static Image ScaleByPercent(Image imgPhoto, int Percent)
        {
            float nPercent = ((float)Percent / 100);            int sourceWidth = imgPhoto.Width;
            int sourceHeight = imgPhoto.Height;
            int sourceX = 0;
            int sourceY = 0;            int destX = 0;
            int destY = 0;
            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);            Bitmap bmPhoto = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);            Graphics grPhoto = Graphics.FromImage(bmPhoto);
            grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;            grPhoto.DrawImage(imgPhoto,
             new Rectangle(destX, destY, destWidth, destHeight),
             new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
             GraphicsUnit.Pixel);            grPhoto.Dispose();
            return bmPhoto;
        }
请高手指教,谢谢我想要的效果是类似ACDsee那样的简单的图片放大功能,把图片直接单击就可以放大,而不是放到另一个图片保存时才能看到放大。至于图像的失真处理,如果高手们有办法解决,小生将不胜感激!

解决方案 »

  1.   

    你的代码缩放是没有问题的啊. 你没有做显示的部分吧.你可以用两个PictureBox控件来显示图像就可以看到效果. 注意的是要设定好PictureBox的SizeMode属性.
      

  2.   

    能否给我一个具体的实例,我来学习一下,,我想要得到类似ACDsee那种的,单击button或者用pictureBox1_Click就可以实现整张图片的放大。请问高手做过这种图片放大的软件吗?我现在不太明白,放大的核心算法,另外,能否用一个pictureBox就可以实现。在picturebox外套一个父窗体panel。肯请高手指教