Using BinaryImage to return image to another app

3 posts, 0 answers
  1. robertgalvinjr
    robertgalvinjr avatar
    36 posts
    Member since:
    Jun 2006

    Posted 29 Dec 2009 Link to this post

    I have an Adobe Flash app that needs to retrieve an image from a URL on a webserver. If I just put the radbinary image control inside an ASPX page I can see the image if I browse directly to the page. But the flash application doesn't think it is in image. How can I do this?
  2. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 29 Dec 2009 Link to this post

    I dont know much about flash, but can you serve it up in an ASHX instead?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. robertgalvinjr
    robertgalvinjr avatar
    36 posts
    Member since:
    Jun 2006

    Posted 30 Dec 2009 Link to this post

    Figured it out - has nothing to do with RadBinary image - but in case anyone is wondering:

      protected void Page_Load(object sender, EventArgs e)  
        {  
     
            int pptID = 0;  
            if (Request.QueryString["pptID"] != null)  
                pptID = Convert.ToInt32(Request.QueryString["pptID"]);  
     
            int sNum = 1;  
            if (Request.QueryString["sNum"] != null)  
                sNum = Convert.ToInt32(Request.QueryString["sNum"]);  
                dbDataDataContext db = new dbDataDataContext();  
                PPT p = db.PPTs.Where(pt => pt.PPTID == pptID).FirstOrDefault();  
                if (p != null)  
                {  
                     
                    PPTImage pImage = db.PPTImages.Where(pi => pi.PPTID == Convert.ToInt32(pptID)   
                        && pi.SlideNum == sNum).FirstOrDefault();  
                    if (pImage != null)  
                    {  
                        Response.ContentType = pImage.MimeType;  
                         
                          
                         
                        byte[] bytes = pImage.FileBinary.ToArray();  
                        System.Data.Linq.Binary fileBinary = new System.Data.Linq.Binary(bytes);  
     
                        //resize graphic down to standard 64x64 size for all avatars  
                        MemoryStream ms = new MemoryStream(bytes);  
                        drawing.Image image = drawing.Image.FromStream(ms);  
                        int w = 640;  
                        int h = 480;  
                        if (Request.QueryString["w"] != null)  
                        {  
                            try 
                            {  
                                w = Convert.ToInt32(Request.QueryString["w"]);  
                            }  
                            catch 
                            {  
                            }  
                        }  
                        if (Request.QueryString["h"] != null)  
                        {  
                            try 
                            {  
                                h = Convert.ToInt32(Request.QueryString["h"]);  
                            }  
                            catch 
                            {  
                            }  
                        }  
                        drawing.Image resizedImage = resizeImage(image, new drawing.Size(w, h));  
                        //change byte array to smaller sized file after resize  
                        MemoryStream msC = new MemoryStream();  
                        drawing.Imaging.ImageFormat iFormat = resizedImage.RawFormat;  
     
                        resizedImage.Save(msC, System.Drawing.Imaging.ImageFormat.Jpeg);  
                        bytes = msC.ToArray();  
                        Response.BinaryWrite(bytes);  
                          
                    }  
                }  
                  
              
        }  
     
        private drawing.Image resizeImage(drawing.Image imgToResize, drawing.Size size)  
        {  
            int sourceWidth = imgToResize.Width;  
            int sourceHeight = imgToResize.Height;  
     
            float nPercent = 0;  
            float nPercentW = 0;  
            float nPercentH = 0;  
     
            nPercentW = ((float)size.Width / (float)sourceWidth);  
            nPercentH = ((float)size.Height / (float)sourceHeight);  
     
            if (nPercentH < nPercentW)  
                nPercent = nPercentH;  
            else 
                nPercent = nPercentW;  
     
            int destWidth = (int)(sourceWidth * nPercent);  
            int destHeight = (int)(sourceHeight * nPercent);  
     
            drawing.Bitmap b = new drawing.Bitmap(destWidth, destHeight);  
            drawing.Graphics g = drawing.Graphics.FromImage((drawing.Image)b);  
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;  
     
            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);  
            g.Dispose();  
     
            return (drawing.Image)b;  
        }  
     
       
Back to Top