Modify GetTempFilePath (PLEASE HEEEEEEEEEEEEELP!)

  •  05-03-2011, 9:37 AM

    Modify GetTempFilePath (PLEASE HEEEEEEEEEEEEELP!)

    Need to create my own GetTempFilePath, is this can be done?
     
     On UploadPhoto_FileUploaded, need to save it to another dir if i can duplicate the GetTempFilePath maybe it would help.
     
    PLEASE HEEEEEEEEEEEEELP!
     

     protected void UploadPhoto_FileUploaded(object sender, UploaderEventArgs args)
        {
            try
            {
                System.Drawing.Bitmap img;            
                using (Stream stream = args.OpenStream())
                {
                    img = new System.Drawing.Bitmap(stream);
                }
                using (img)
                {
                    
                    if (img.Width > MaxWidth || img.Height > MaxHeight)
                    {
                        double scale = Math.Max(img.Width / MaxWidth, img.Height / MaxHeight);
                        int w = (int)(img.Width / scale);
                        int h = (int)(img.Height / scale);
                        //System.Drawing.Image.GetThumbnailImageAbort

                        try
                        {
                            using (System.Drawing.Image thumb = new System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
                            {
                                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(thumb))
                                {
                                    g.DrawImage(img
                                        , new System.Drawing.Rectangle(0, 0, w, h)
                                        , new System.Drawing.Rectangle(0, 0, img.Width, img.Height)
                                        , System.Drawing.GraphicsUnit.Pixel);
                                }
                                thumb.Save(args.GetTempFilePath(), System.Drawing.Imaging.ImageFormat.Png);
                                //Here need to RESIZE AGAIN and save to another DIR
                                LabelPhotoError.Text = "The image is uploaded and resized. "+args.GetTempFilePath();
                            }
                           
                        }
                        catch (Exception x)
                        {
                            LabelPhotoError.Text = w + ":" + h + ":" + x.ToString();
                            args.Delete();
                        }
                    }
                }
            }
            catch (Exception x)
            {
                LabelPhotoError.Text = x.ToString();
                args.Delete();
            }
        }
    Filed under: ,
View Complete Thread