Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    URGE AIUTOOOO SU upload img

    ciao ragazzi, innanzi tutto AUGURI A TUTTI.

    ho un urgente aiuto su questo script con cui riesco ad uploadare due file, uno delle dimensioni naturali e l'altro in base al resize che gli dò io.

    il problema è che il file che viene ridotto col resize perde un casino di qualità

    si rovina troppo.

    da cosa può dipendere. GRAZIE e spero mi possiate aiutare

    codice:
    <%@ Page Language="C#" %>
    <%@ import Namespace="System.Drawing.Imaging" %>
    <script runat="server">
    
       void UploadBtn_Click(Object sender, EventArgs e)
        {
          
    	   String UploadedFile = MyFile.PostedFile.FileName;
    	   int ExtractPos =	UploadedFile.LastIndexOf("\\") + 1;
    	 
    	   //to retrieve only Filename from the complete path
    	   String UploadedFileName =  UploadedFile.Substring(ExtractPos,UploadedFile.Length - ExtractPos);
           
    	   
    	   // Display information about posted file. Div is invisible by default	  
    	   FileName.InnerHtml = UploadedFileName;
           MyContentType.InnerHtml = MyFile.PostedFile.ContentType;
           ContentLength.InnerHtml = MyFile.PostedFile.ContentLength.ToString();
    
           FileDetails.Visible = true; //div is made visible
           // Save uploaded file to server at the in the Pics folder
           MyFile.PostedFile.SaveAs(Request.PhysicalApplicationPath + "public\\" + "img\\" + UploadedFileName );
    
    		//thumbnail creation starts
    		try
    		{
    		//Read in the image filename whose thumbnail has to be created
    		 String imageUrl=  UploadedFileName;
    
    		//Read in the width and height
    		int imageHeight =Convert.ToInt32(h.Text);
    		int imageWidth  = Convert.ToInt32(w.Text); 
    		
    		//You may even specify a standard thumbnail size
    		//int imageWidth  = 70; 
    		//int imageHeight = 70;
    	 
    		if (imageUrl.IndexOf("/") >= 0 || imageUrl.IndexOf("\\") >= 0 )
    		{
    		  //We found a / or \
    		  Response.End();
    		}
    
    		//the uploaded image will be stored in the Pics folder.
    		//to get resize the image, the original image has to be accessed from the
    		//Pics folder
    		//Adesso image1 visualizza il percorso public/pics senza / il percorso è dalla dir principale
    		imageUrl = "/public/img/" + imageUrl;
    		
    		System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl));
    
    		System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
    
    		System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, IntPtr.Zero);
    			
    		//We need to create a unique filename for each generated image
    		DateTime MyDate = DateTime.Now;
    
    	    String MyString  = MyDate.ToString("ddMMyyhhmmss") + ".png" ;
    
    		//Save the thumbnail in Png format. You may change it to a diff format with the ImageFormat property
    	    thumbNailImg.Save ( Request.PhysicalApplicationPath + "public\\" + "ico\\"  + "ico_" + UploadedFileName);		
    //	    thumbNailImg.Save ( Request.PhysicalApplicationPath + "public\\" + "ico\\" +   MyString , ImageFormat.Png);
    
    	   thumbNailImg.Dispose();
    
    		//Display the original & the newly generated thumbnail
    		// da qui si sceglie il percorso da cui visualizzare le immagini
    	   Image1.AlternateText = "Original image";
    	   Image1.ImageUrl="/public\\img\\" + UploadedFileName;
    			
    	   Image2.AlternateText = "Thumbnail";
    	   Image2.ImageUrl="/public\\ico\\" + "ico_" + UploadedFileName;
    	 }
    
    	 catch(Exception ex)
    	 {
    		Response.Write("An error occurred - " + ex.ToString());
    	 }
    
    }
    
    //this function is reqd for thumbnail creation
    public bool ThumbnailCallback()
    {
    	return false;
    }
    
    </script>
    <html>
    <head>
    </head>
    <body>
        <form action="fileupload.aspx" method="post" enctype="multipart/form-data" runat="server">
            <h4>Upload & save generated thumbnail 
            </h4>
            Select File To Upload to Server: 
            <input id="MyFile" type="file" runat="server" />
            
    
            Desired Width of Thumbnail&nbsp&nbsp: 
            <asp:TextBox id="w" runat="server" name="w" Width="38px" value="300"></asp:TextBox>
            
    
    		Desired Height of Thumbnail&nbsp&nbsp: 
            <asp:TextBox id="h" runat="server" name="h" Width="38px" value="225"></asp:TextBox>
            
    
            <input type="submit" value="Upload!" runat="server" onserverclick="UploadBtn_Click" />
            
    
            
    
            <hr/>
            <div id="FileDetails" runat="server" visible="false">FileName: <span id="FileName" runat="server"></span>
    
            ContentType: <span id="MyContentType" runat="server"></span>
    
            ContentLength: <span id="ContentLength" runat="server">bytes 
                </span>
    
    
            Original Image : <asp:Image id="Image1" runat="server"></asp:Image></br>
    		Resized  Image : <asp:Image id="Image2" runat="server"></asp:Image>
            </div>
        </form>
    </body> 
    </html>
    ---------------------------
    danielix05

  2. #2

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.