有一300*300的画布,
上传后的图片进行等比压缩,压缩后的宽度最小是300,压缩后的高度最小是200。原图片限定的大小是小于等于1M的,那么原图的原始图片长宽应该符合什么条件呢;当然这里面有个分辨率的不同,暂以72/(像素/英寸)来考虑,拜谢了

解决方案 »

  1.   

    问的比较矛盾,不够清晰...
    "比如,如果宽>300高<200,则已宽300进行等比压缩到宽=300,高自适应,如果宽<300而高>200,则已高=200进行等比压缩(这两种压缩会导致一边小于原预期值,等比吗,不然就变形..)...然后在判断高>200切宽>300..........等等其他很多情况..."
    真不知道你这是什么意思....怎么像素也撤进来了...
      

  2.   

    /// <summary>
            /// </summary>
            /// <param name="outCeshiPath">要压缩的图片的路径</param>
            /// <param name="converPhoto">压缩后保存路径</param>
            /// <res>
            /// </res>
            public static void CompressMinImage(string pPath, string outCeshiPath, string converPhoto)
            {
                int width = 300;
                int height = 200;
                    Image img = Image.FromFile(outCeshiPath);
                    int W = img.Width - width;
                    int H = img.Height - height;
                    if (img.Width >= 300&& img.Height >= 200)
                    {
                    Image originalImg = Image.FromFile(outCeshiPath);
                    Bitmap bmpOut = new Bitmap(width, height, PixelFormat.Format24bppRgb);
                    Graphics g = Graphics.FromImage(bmpOut);
                    g.DrawImage(originalImg, new Rectangle(0, 0, width, height), new Rectangle(0, 0, width, height), GraphicsUnit.Pixel);
                    bmpOut.Save(converPhoto, ImageFormat.Jpeg);
                    originalImg.Dispose();
                    bmpOut.Dispose();
                    g.Dispose();
                }else{
                      //xxxxxxxxxx
                  }        }