Ciao a tutti.
Sto realizzando una pagina che contiene un elenco di immagini salvate su database (non l' indirizzo dell' immagine, proprio l' immagine). Ogni immagine deve avere una larghezza e un' altezza massime. L' immagine deve quindi essere manipolata.
Lo faccio con un handler, usando l' oggetto Bitmap, il Graphics e il Brush presi da System.Drawing. Il problema è che l' immagine dopo l' elaborazione risulta sgranata, con un effetto bruttissimo. So che non è colpa della risoluzione dell' immagine perchè prima avevo fatto lo stesso lavoro con aspjpeg, un componente a pagamento. Non sono molto ferrato sull' elaborazione delle immagini, sapete dirmi se sbaglio qualcosa? Oppure è solo lo spazio System.Drawing che non è all' altezza?

Ecco il codice del mio handler:

codice:
public void ProcessRequest(HttpContext context)
    {
        MySqlConnection conn = new MySqlConnection();
        float w, h, rap;
        Bitmap img = null, img_elab = null;

        try
        {
            conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            conn.Open();
            
            MySqlCommand comm = new MySqlCommand("SELECT immagine FROM prod WHERE id=@id", conn);
            comm.Parameters.AddWithValue("id", context.Request.QueryString["id"]);
            MySqlDataReader dataread = comm.ExecuteReader();
            if (dataread.HasRows)
            {
                dataread.Read();
                System.IO.MemoryStream stream = new System.IO.MemoryStream((byte[])dataread[0]);
                img = new Bitmap(stream);
                w = (float)img.Width; h = (float)img.Height;
                rap = h / w;
                h = ALTEZZA_MAX;
                w = h / rap;
                if (w > LARGHEZZA_MAX)
                {
                    w = LARGHEZZA_MAX;
                    h = rap * w;
                }
                img_elab = new Bitmap((int)w, (int)h);
                Graphics grap = Graphics.FromImage(img_elab);
                SolidBrush brush = new SolidBrush(Color.White);

                grap.FillRectangle(brush, new Rectangle(0, 0, (int)w, (int)h));
                grap.DrawImage(img, 0, 0, (int)w, (int)h);
                
                System.IO.MemoryStream s = new System.IO.MemoryStream();
                img_elab.Save(s, System.Drawing.Imaging.ImageFormat.Jpeg);
                Byte[] abyte = s.ToArray();
                context.Response.OutputStream.Write(abyte, 0, abyte.Length);
                dataread.Close();
            }
        }
        catch
        {
            gestisci_errore();
        }
        finally
        {
            conn.Close();
        }
    }