Friday, April 24, 2015

iPhone Launch Screen Sizes

iPhone Portrait iOS 8

Retina HT 5.5 = 1242 X 2208
Retna HD 4.7 = 750 X 1134

iPhone Landscape iOS 8

Retina HD 5.5  2208 X 1242

iPhone Portrait iOS 7,8

2X 640 X 960
Retina 4 640 x 1136

iPad Portrate iOS 7,8

1x 768 X 1024
2x 1536 X 2048

iPad Landscape iOS 7,8

1x 1024 X 768
2X 2048 X 1536

iPhone Portrait iOS 5,6

1x 320 X 480
2x 640 X 960
Retina 4 640 X 1136

iPad POrtrait (Without Status Bar) iOS 5,6

1x 768 X 1004
2X 1536 X 2008

iPad Portrait iOS 5,6

1X 768 X 1024
2x 1536 X 2048

iPad Landscape (Without Status Bar) iOS 5,6

1X 1024 X 748
2X 2048 X 1496

iPad Landscapd iOS 5,6

1x 1024 X 768
2X 2048 X 1536

Wednesday, September 19, 2012

How to crop and compress an bitmap file and load it as a Meta File

    Bitmap croppedImage = bitmap.Clone(new Rectangle(0, top, bitmap.Width, limit - top), bitmap.PixelFormat);
    System.Drawing.Image cha = image;
    Graphics g = null;                                    
    ImageCodecInfo imageCodecInfo = null;
    System.Drawing.Imaging.Encoder encoder;
    EncoderParameter encoderParameter;
    EncoderParameters encoderParameters;
    ImageCodecInfo[] encoders;
    encoders = ImageCodecInfo.GetImageEncoders();
    for (int j = 0; j < encoders.Length; ++j)
        if (encoders[j].MimeType == "image/tiff")
            imageCodecInfo = encoders[j];
    encoder = System.Drawing.Imaging.Encoder.Compression;
    encoderParameters = new EncoderParameters(1);
    encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionLZW);
    encoderParameters.Param[0] = encoderParameter;
    string path = this.TempFileName("tif");
    croppedImage.Save(path, imageCodecInfo, encoderParameters);
    System.Drawing.Image m = Metafile.FromFile(path);

Saturday, December 17, 2011

How to validate a number between 0-24 with Java Scripts

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <script language="javascript" type="text/javascript">
        function checkIt(obj, evt) {
            evt = (evt) ? evt : window.event
            var charCode = (evt.which) ? evt.which : evt.keyCode
            if ((charCode < 45 || charCode > 57) && charCode != 8 && charCode != 37 && charCode != 39) {
                alert("This field accepts numbers only")
                return false
            }
            var t = (charCode / 1) - 48;
            var v = obj.value + t;
            var value = v / 1;
            if(value > 24){ 
                alert("Number should be less than 24");
                return false;
            }
            return true
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox runat="server" ID="txtNumber" onKeyPress='javascript:return checkIt(this, event)' />
    </div>
    </form>
</body>
</html>

Wednesday, December 14, 2011

How to retain the password in a postback

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test Page</title>
    <script runat="server">
        public string Password
        {
            get { return ViewState["Password"as string; }
            set { this.ViewState["Password"] = value; }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (this.IsPostBack)
            {
                if (!string.IsNullOrEmpty(this.txtPassword.Text))
                    this.Password = this.txtPassword.Text;
                this.txtPassword.Attributes.Add("value"this.Password ?? string.Empty);
            }
        }
    </script>
</head>
<body>
    <form  id="aspNetForm" runat="server">
        UserName: <asp:TextBox runat="server" ID="txtName" />
        Password: <asp:TextBox runat="server" ID="txtPassword" TextMode="Password" />
        <hr />
        <asp:Button runat="server" ID="btnSave" Text="Save" />
    </form>
</body>
</html>

Tuesday, December 13, 2011

Html Header Tag Sizes

  • H1 - 24pt / 32px
  • H2 - 18pt / 24px
  • H3 - 14pt / 18px
  • H4 - 12pt / 15px
  • H5 - 10pt / 13px
  • H6 - 8pt   / 11px
Above are the default font sizes in points and their approximate sizes in pixels

Friday, August 19, 2011

How to upload a external image link url and save on the disk

 We can get the use of HttpWebRequest and HttpWebResponse to send the request and get the response. Then response.GetResponseStream() will give us a stream of the image where we can use that stream to create a Image object like Image image = Image.FromStream(stream)

Markup:
<%@ Page Language="C#" CodeBehind="Test.aspx.cs" Inherits="ActiveTest.Test" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox runat="server" ID="txtUpload" 
            Text="http://www.web-sphere.co.uk/web/websphere/blog/bloggerheader.jpg" />
        <asp:Button runat="server" ID="btnUpload" OnClick="Upload" Text="Upload" />
    </div> 
    </form>
</body>
</html>
Code:
namespace ActiveTest
{
    public partial class Test : Page
    {
        protected void Upload(object sender, EventArgs e)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.txtUpload.Text);
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            Stream stream = response.GetResponseStream();         
            ///
            /// use response content type to findout the image type, 
            /// here I just use jpg to simplify the story.
            /// 
            System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
            image.Save(this.Server.MapPath(string.Format("~/Uploads/{0}.jpg",Guid.NewGuid())));
        }
    }
}

Tuesday, November 16, 2010

How to output web page as MS word document

public partial class Test : Page
{
    protected override void Render(HtmlTextWriter writer)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/msword";
        StringBuilder sb = new StringBuilder();
        StringWriter stringWriter = new StringWriter(sb);
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        base.Render(htmlTextWriter);
        Response.Write(sb.ToString());
        Response.End();            
    }
}

Friday, November 12, 2010

How to keep track of selected file during a postback.

When you select a file and then do a postback, you will lose your selected file. This is because there is no ViewState for posted file in asp.net FileUpload control. This example is to demonstrate an idea of how to save the file in any-postback and if there is a selected file, then we save the file and show the fileName in a hyperlink to download or view,
Example:
<%@ Page Language="C#" %>
<html>
<head id="Head1" runat="server">
    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (this.fuFile.HasFile)
            {                
                string filePath = Server.MapPath(string.Format("~/Uploads/{0}"this.fuFile.FileName));
                if (!System.IO.File.Exists(filePath))
                {
                    this.fuFile.SaveAs(filePath);
                    this.linkSelectedFile.NavigateUrl = this.ResolveUrl(string.Format("~/Uploads/{0}"this.fuFile.FileName));
                    this.linkSelectedFile.Text = this.fuFile.FileName;
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        Select a File: <asp:FileUpload runat="server" ID="fuFile" />
        <asp:HyperLink runat="server" ID="linkSelectedFile" />
        <hr />
        <asp:DropDownList runat="server" ID="ddlItems" AutoPostBack="true">
            <asp:ListItem>Item One</asp:ListItem>
            <asp:ListItem>Item Two</asp:ListItem>
        </asp:DropDownList>
    </form>
</body>
</html>

Tuesday, November 02, 2010

How to disable past days in asp.net calender control

<%@ Page Language="C#" %>
<html>   
<head id="Head1" runat="server">  
    <script runat="server">
        protected void DisablePastDays(object sender, DayRenderEventArgs e)
        {
            if (e.Day.Date < DateTime.Now)
            {
                e.Cell.Enabled = false;
                e.Day.IsSelectable = false;
                e.Cell.BackColor = System.Drawing.Color.Gray;
            }
        } 
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Calendar runat="server" ID="calDate" OnDayRender="DisablePastDays" />
    </form>
</body>
</html>

How to add detail textbox opon the check of a check box

Demo:
Example:
Markup:
<%@ Page Language="C#" %>
<html>   
<head id="Head1" runat="server">  
</head>
<body>
    <form id="form1" runat="server">
        <asp:FreeCheckBox runat="server" 
            ID="freeCheckBox" 
            DetailPlaceHolderId="phDetails" 
            Text="Are you disabled?" 
            DetailLabel="Please please provide details" />
        <asp:PlaceHolder runat="server" ID="phDetails" />
        <hr />
        <asp:Button runat="server" ID="btnSave" Text="Save" />
    </form>
</body>
</html>
Control:
public class FreeCheckBox : CheckBox
{
    private TextBox txtDetail;
    private Panel pnlDetail;
    private string script = @"
    function ShowHideDetailPanel(detailPanel, source) {            
        var panel = document.getElementById(detailPanel);
        if (panel == undefined) return;
        if (source.checked == true)
            panel.style.display = ""block"";
        else
            panel.style.display = ""none"";
    }
";
    public string DetailLabel { getset; }
    public string Details { getset; }
    public string DetailPlaceHolderId { getset; }
    public bool IsMultiline { getset; }
    public FreeCheckBox()
    {
        this.DetailPlaceHolderId = string.Empty;
        this.IsMultiline = false;
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.CreateControlHeirarchy();
    }
    public void CreateControlHeirarchy()
    {
        this.pnlDetail = new Panel() { ID = string.Concat(this.ID, "_DetailPanel"), CssClass = "DetailPanel" };
        this.txtDetail = new TextBox() { ID = string.Concat(this.ID, "_TextBox"), 
                                            CssClass = "DetailTextBox", TextMode = TextBoxMode.MultiLine };
        if (this.IsMultiline) this.txtDetail.TextMode = TextBoxMode.MultiLine;
        this.pnlDetail.Controls.Add(new Label() { Text = this.DetailLabel, CssClass = "DetailLabel" });
        this.pnlDetail.Controls.Add(this.txtDetail);
        PlaceHolder phDetail = this.Page.FindControl(this.DetailPlaceHolderId) as PlaceHolder;
        Control parent = this.Parent;
        while (phDetail == null)
        {
            phDetail = parent.FindControl(this.DetailPlaceHolderId) as PlaceHolder;
            if (phDetail == null) parent = parent.Parent;
            if (parent == nullbreak;
        }
        if (phDetail != null) phDetail.Controls.Add(pnlDetail);
        this.Attributes.Add("onclick", 
                string.Format("javascript:ShowHideDetailPanel('{0}', this)", pnlDetail.ClientID));
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (this.Checked)
            this.pnlDetail.Attributes.Add("style""display:block;");
        else
            this.pnlDetail.Attributes.Add("style""display:none;");
    }
    protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
    {
        bool value = base.LoadPostData(postDataKey, postCollection);
        if (this.Checked)
            this.Details = this.txtDetail.Text;
        return value;
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        this.Page.ClientScript.RegisterClientScriptBlock(
                this.GetType(), this.GetType().Name, this.script, true);
    }
}

How to download images

Demo:
Code:
<%@ Page Language="C#" %>
<html>   
<head id="Head1" runat="server">  
    <script runat="server">
        public void DownloadPicture(object sender, EventArgs e)
        {
            ImageButton button = sender as ImageButton;
            if (button != null)
            {
                string fileName = button.CommandArgument;
                this.Response.AddHeader("content-disposition", 
                    string.Format("attachment;filename={0}", Path.GetFileName(fileName)));
                this.Response.ContentType = "image/jpg";
                this.Response.WriteFile(this.Server.MapPath("~/Images/" + fileName));
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ImageButton runat="server" ID="btnPic1" Text="Pic 1" CommandArgument="Image1.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image1.jpg" />
        <asp:ImageButton runat="server" ID="btnPic2" Text="Pic 2" CommandArgument="Image2.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image2.jpg" />
        <asp:ImageButton runat="server" ID="btnPic3" Text="Pic 3" CommandArgument="Image3.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image3.jpg" />
        <asp:ImageButton runat="server" ID="btnPic4" Text="Pic 4" CommandArgument="Image4.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image4.jpg"/>
        <asp:ImageButton runat="server" ID="btnPic5" Text="Pic 5" CommandArgument="Image5.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image5.jpg"/>
    </form>
</body>
</html>

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...