Exemplo n.º 1
0
    protected void drawpicture(picturelayout pl, sessionpicture sp)
    {
        Bitmap fpicture = new Bitmap(HostingEnvironment.ApplicationPhysicalPath + "\\uploadedpictures\\" + sp.filename);

        // the hard way is to cope with the panning and zooming and to also draw the border.
        Region clip = grapher.Clip;

        grapher.SetClip(new Rectangle(pl.left, pl.top, pl.width, pl.height));
        //code to use if we have rect of image to draw
        //grapher.DrawImage(fpicture, new Rectangle(pl.left, pl.top, pl.width, pl.height), new Rectangle(sp.left, sp.top, sp.right - sp.left, sp.bottom - sp.top), GraphicsUnit.Pixel);
        // code to use it we have position and zoom
        grapher.DrawImage(fpicture, pl.left + sp.left, pl.top + sp.top, sp.imagewidth * sp.scale, sp.imageheight * sp.scale);
        //grapher.DrawImage(fpicture, pl.left, pl.top, sp.imagewidth * sp.scale, sp.imageheight * sp.scale);
        grapher.SetClip(clip, CombineMode.Replace);

        if (sp.borderfilename != null)
        {
            fpicture = new Bitmap(HostingEnvironment.ApplicationPhysicalPath + "\\borders\\" + sp.borderfilename);
            grapher.DrawImage(fpicture, pl.left, pl.top, pl.width, pl.height);
        }

        if (pl.borderwidth > 0)
        {
            // top edge
            grapher.FillRectangle(pl.bordercolour.getsolidbrush, pl.left - pl.borderwidth, pl.top - pl.borderwidth, pl.width + pl.borderwidth, pl.borderwidth);
            // bottom edge
            grapher.FillRectangle(pl.bordercolour.getsolidbrush, pl.left - pl.borderwidth, pl.top + pl.height, pl.width + pl.borderwidth, pl.borderwidth);
            // left edge
            grapher.FillRectangle(pl.bordercolour.getsolidbrush, pl.left - pl.borderwidth, pl.top, pl.borderwidth, pl.height);
            // right edge
            grapher.FillRectangle(pl.bordercolour.getsolidbrush, pl.left + pl.width, pl.top - pl.borderwidth, pl.borderwidth, pl.height + pl.borderwidth + pl.borderwidth);
        }

        // also want to conditionally draw the low res or the full res picture
    }
Exemplo n.º 2
0
 // overrides colectionbase.add, mainly for use by xmlserialiser
 public virtual void Add(picturelayout pl)
 {
     this.List.Add(pl);
     fpictures.Add(pl.name, pl);
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        Single xscale, yscale;

        // get the article index to choose from the query string
        try
        {
            fpictureindex = Convert.ToInt16(Request.QueryString["picture"]);
        }
        catch
        {
            fpictureindex = 0;
        }

        // get layout and picture info from the seesion, redirect to home page if we don't have all that we need
        try
        {
            spl = (sessionpagelayout)Session["sessionpagelayout"];
            if (spl != null)
            {
                pl = ceddio.loadpagelayout(spl.pagelayoutfilename);
            }
            layoutinfo = pl.pictures[pictureindex];
            // get the total number of articles
            fpicturestotal = pl.pictures.Count;

            // get the prompt for the current article
            fpicturename   = pl.pictures[pictureindex].name;
            fpictureprompt = pl.pictures[pictureindex].prompt;
            sps            = (sessionpictures)Session["sessionpictures"];
            if (sps == null)
            {
                sps = new sessionpictures();
                Session["sessionpictures"] = sps;
            }
        }
        catch
        {
            Response.Redirect("default.aspx", true);
        }

        // if this is the first load of this page then save an image containing just the text of the articles. This will be overlaid on the uploaded pictures so that the user can line up the picture and the headline nicely.
        if ((Request.UrlReferrer == null) || (Request.Url.AbsolutePath != Request.UrlReferrer.AbsolutePath))
        {
            Session["articleoverlayfilename"] = "";
            // get an image containing just the text overlay
            Bitmap barticles = articlesdrawer.drawarticles(pl, (sessionarticles)Session["sessionarticles"], (sessioncustomisations)Session["sessioncustomisation"], sps, true);
            string articleoverlayfilename = Guid.NewGuid().ToString() + ".png";
            barticles.Save(Server.MapPath("~/articleoverlays/") + articleoverlayfilename, ImageFormat.Png);
            Session["articleoverlayfilename"] = articleoverlayfilename;
        }

        // work out the scaling for this picture so that all pictures take up the same space on screen when positioning. This is so that small pictures are easily visible and so large pictures are not unmanageably large
        xscale    = (400f / (Single)layoutinfo.width);
        yscale    = (300f / (Single)layoutinfo.height);
        pagescale = Math.Min(xscale, yscale);

        // get the session info for this picture, if there is any
        try { picinfo = sps.picture(fpicturename); }
        catch { picinfo = null; }

        if (Page.IsPostBack == true)
        {
            return;
        }

        // show hide the controls for an optional picture
        poptional.Visible = layoutinfo.optional;

        // hide the javascript if there is no picture to work with
        if ((picinfo == null) || (System.IO.File.Exists(HostingEnvironment.ApplicationPhysicalPath + "\\uploadedpictures\\" + picinfo.filename)) == false)
        {
            pimgscript.Visible = false;
            //pcrop.Visible = false;
        }
        else
        {
            //
        }

        DataBind();
    }