Exemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            switch (this.cookPageType)
            {
            case PIKCV.COM.Enumerations.PageType.Employee:
                this.ImageSaveType = PIKCV.COM.Enumerations.ImageSaveType.EmployeeBig;
                break;

            case PIKCV.COM.Enumerations.PageType.Company:
                this.ImageSaveType = PIKCV.COM.Enumerations.ImageSaveType.Company;
                break;
            }
        }
    }
Exemplo n.º 2
0
    public string SendFile()
    {
        try
        {
            string FilePath          = "";
            string FileName          = fupImg.FileName;
            string TempFilePath      = "";
            string SaveFileName      = "";
            string SaveFileSmallName = "";
            string FileSmallName     = "";
            string FileExtention     = "";

            switch (this.ImageSaveType)
            {
            case PIKCV.COM.Enumerations.ImageSaveType.EmployeeBig:
                FilePath          = Request.MapPath(this.Config(PIKCV.COM.EnumUtil.Config.UserImagePath));
                TempFilePath      = Request.MapPath(this.Config(PIKCV.COM.EnumUtil.Config.UserImagePath));
                SaveFileSmallName = this.smUserID.ToString();
                break;

            case PIKCV.COM.Enumerations.ImageSaveType.EmployeeSmall:
                FilePath          = Request.MapPath(this.Config(PIKCV.COM.EnumUtil.Config.UserImagePathSmall));
                TempFilePath      = Request.MapPath(this.Config(PIKCV.COM.EnumUtil.Config.UserImagePathSmall));
                SaveFileSmallName = this.smUserID.ToString();
                break;

            case PIKCV.COM.Enumerations.ImageSaveType.Company:
                FilePath          = Request.MapPath(this.Config(PIKCV.COM.EnumUtil.Config.CompanyImagePath));
                TempFilePath      = Request.MapPath(this.Config(PIKCV.COM.EnumUtil.Config.CompanyImagePath));
                SaveFileSmallName = this.smCompanyID.ToString();
                break;

            default:
                break;
            }

            int iPoint = FileName.LastIndexOf(".");

            if (iPoint != -1)
            {
                FileExtention = FileName.Substring(iPoint);
                FileSmallName = FileName.Substring(0, iPoint);
            }

            SaveFileName = SaveFileSmallName + FileExtention;

            if (fupImg.PostedFile.ContentLength > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.ImageMaxLenght)))
            {
                //lbMessage.Text = "1 MB'dan Büyük Resim Giremessiniz. Lütfen Daha Küçük Boyutta Bir Fotoðraf Giriniz.";
                return("");
            }

            int verNum = 1;
            while (System.IO.File.Exists(FilePath + FileName))
            {
                FileName = FileSmallName + "_" + verNum.ToString() + FileExtention;
                verNum  += 1;
            }

            verNum = 1;
            while (System.IO.File.Exists(FilePath + SaveFileName))
            {
                SaveFileName = SaveFileSmallName + "_" + verNum.ToString() + FileExtention;
                verNum      += 1;
            }
            DeleteImage("Temp" + FileName, TempFilePath);


            fupImg.SaveAs(TempFilePath + ("Temp" + FileName));

            //boyut çok küçük mü kontrolü
            if (this.ImageSaveType == PIKCV.COM.Enumerations.ImageSaveType.EmployeeBig)
            {
                if (CheckIfSizeTooSmall(TempFilePath + ("Temp" + FileName)))
                {
                    ImageTooSmall();
                    return("");
                }
            }
            ////////////////////////////////

            ChangeSize(TempFilePath + ("Temp" + FileName), FilePath + SaveFileName);
            if (this.ImageSaveType == PIKCV.COM.Enumerations.ImageSaveType.EmployeeBig)
            {
                this.ImageSaveType = PIKCV.COM.Enumerations.ImageSaveType.EmployeeSmall;
                FilePath           = Request.MapPath(this.Config(PIKCV.COM.EnumUtil.Config.UserImagePathSmall));
                ChangeSize(TempFilePath + ("Temp" + FileName), FilePath + SaveFileName);
            }
            DeleteImage(("Temp" + FileName), TempFilePath);
            if (RaiseEvents)
            {
                ImageUploaded(SaveFileName);
            }
            return(SaveFileName);
        }
        catch (Exception)
        {
            return("");
        }
    }
Exemplo n.º 3
0
    private void Convert()
    {
        bool    blnKeepAspectRation;
        bool    blnFactorToWidth;
        decimal decFactor = 0;
        string  strHeight;
        string  strWidth;
        int     intOriginalHeight;
        int     intOriginalWidth;
        int     intNewWidth;
        int     intNewHeight;

        System.Drawing.Image imgNewImage;

        intOriginalHeight = imgConverted.Height;
        intOriginalWidth  = imgConverted.Width;

        strWidth  = "*";
        strHeight = "*";

        blnKeepAspectRation = false;
        blnFactorToWidth    = false;

        switch (this.ImageSaveType)
        {
        case PIKCV.COM.Enumerations.ImageSaveType.EmployeeBig:
            if (intOriginalWidth > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.UserImageWidth)))
            {
                int     TestingHeight    = 0;
                decimal TestingdecFactor = 0;
                strWidth         = this.Config(PIKCV.COM.EnumUtil.Config.UserImageWidth);
                TestingdecFactor = decimal.Parse(strWidth) / decimal.Parse(imgConverted.Width.ToString());
                TestingHeight    = (int)Math.Floor(intOriginalHeight * TestingdecFactor);
                if (TestingHeight > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.UserImageHeight)))
                {
                    strWidth  = "*";
                    strHeight = this.Config(PIKCV.COM.EnumUtil.Config.UserImageHeight);
                }
            }
            else if (intOriginalHeight > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.UserImageHeight)))
            {
                strHeight = this.Config(PIKCV.COM.EnumUtil.Config.UserImageHeight);
            }
            break;

        case PIKCV.COM.Enumerations.ImageSaveType.EmployeeSmall:
            if (intOriginalWidth > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.UserImageWidthSmall)))
            {
                int     TestingHeight    = 0;
                decimal TestingdecFactor = 0;
                strWidth         = this.Config(PIKCV.COM.EnumUtil.Config.UserImageWidthSmall);
                TestingdecFactor = decimal.Parse(strWidth) / decimal.Parse(imgConverted.Width.ToString());
                TestingHeight    = (int)Math.Floor(intOriginalHeight * TestingdecFactor);
                if (TestingHeight > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.UserImageHeightSmall)))
                {
                    strWidth  = "*";
                    strHeight = this.Config(PIKCV.COM.EnumUtil.Config.UserImageHeightSmall);
                }
            }
            else if (intOriginalHeight > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.UserImageHeightSmall)))
            {
                strHeight = this.Config(PIKCV.COM.EnumUtil.Config.UserImageHeightSmall);
            }
            this.ImageSaveType = PIKCV.COM.Enumerations.ImageSaveType.EmployeeBig;
            break;

        case PIKCV.COM.Enumerations.ImageSaveType.Company:
            if (intOriginalWidth > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.CompanyImageWidth)))
            {
                int     TestingHeight    = 0;
                decimal TestingdecFactor = 0;
                strWidth         = this.Config(PIKCV.COM.EnumUtil.Config.CompanyImageWidth);
                TestingdecFactor = decimal.Parse(strWidth) / decimal.Parse(imgConverted.Width.ToString());
                TestingHeight    = (int)Math.Floor(intOriginalHeight * TestingdecFactor);
                if (TestingHeight > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.CompanyImageHeight)))
                {
                    strWidth  = "*";
                    strHeight = this.Config(PIKCV.COM.EnumUtil.Config.CompanyImageHeight);
                }
            }
            else if (intOriginalHeight > int.Parse(this.Config(PIKCV.COM.EnumUtil.Config.CompanyImageHeight)))
            {
                strHeight = this.Config(PIKCV.COM.EnumUtil.Config.CompanyImageHeight);
            }
            break;
        }

        if (!(strWidth == "*") & !(strHeight == "*"))
        {
            //Width Önemli deðil Height'a göre factor edilecek
            blnKeepAspectRation = false;
        }
        else if (!(strWidth == "*"))
        {
            blnFactorToWidth    = true;
            decFactor           = decimal.Parse(strWidth) / decimal.Parse(imgConverted.Width.ToString());
            blnKeepAspectRation = true;
        }
        //Width belli
        else if (!(strHeight == "*"))
        {
            blnFactorToWidth    = false;
            decFactor           = decimal.Parse(strHeight) / decimal.Parse(imgConverted.Height.ToString());
            blnKeepAspectRation = true;
        }

        if (blnKeepAspectRation)
        {
            if (blnFactorToWidth)
            {
                intNewWidth  = int.Parse(strWidth);
                intNewHeight = (int)Math.Floor(intOriginalHeight * decFactor);
            }
            else
            {
                intNewWidth  = (int)Math.Floor(intOriginalWidth * decFactor);
                intNewHeight = int.Parse(strHeight);
            }
        }
        else
        {
            //img = New Bitmap(img, New Size(CInt(strWidth), CInt(strHeight)))
            intNewWidth  = intOriginalWidth;
            intNewHeight = intOriginalHeight;
        }



        //ms = New MemoryStream()

        imgNewImage = new Bitmap(intNewWidth, intNewHeight);
        System.Drawing.Graphics graphic;
        graphic = System.Drawing.Graphics.FromImage(imgNewImage);
        graphic.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        graphic.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        graphic.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
        graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        graphic.DrawImage(imgConverted, 0, 0, intNewWidth, intNewHeight);
        imgConverted = imgNewImage;
    }