3
Answers

Image to fit in asp page

Photo of hema latha

hema latha

7y
139
1
I am displaying image from a folder using an asp image control in a timer.The image doest not correctly fit into the screen like it gets vertical and hortizontal scroll bars.
 
 
aspx code
 
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="BannerPanel" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="5000" Enabled="false" >
</asp:Timer>
<asp:Button ID="btnDisplay" runat="server" Text="Display " OnClick="btnDisplay_Click" />
<asp:Image ID="Image1" runat="server" style="width: 100%;" />
</ContentTemplate>
</asp:UpdatePanel>
 
 
code behind
 
string localstr = Server.MapPath("~//bin//Images//"+ Filename );
Byte[] bytes = File.ReadAllBytes(localstr);
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
Image1.ImageUrl = "data:image/" + ext + ";base64," + base64String;
 
 

Answers (3)

1
Photo of Manav Pandya
NA 7.1k 24.1k 7y
Hello 
 
As per you told me to use .bmp image , i have used the same 
 
An my code working succesfully :
 
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ImageDemo.aspx.cs" Inherits="ImageDemo.ImageDemo" %>  
  2.   
  3. <!DOCTYPE html>  
  4.   
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head runat="server">  
  7.     <title></title>  
  8.     <style>  
  9.         html {  
  10.             overflow: hidden;  
  11.             -webkit-background-size: 100% auto;  
  12.             -moz-background-size: 100% auto;  
  13.             -ms-background-size: 100% auto;  
  14.             -o-background-size: 100% auto;  
  15.             background-size: 100% auto;  
  16.         }  
  17.   
  18.         body {  
  19.             width: 100%;  
  20.             height: 100%;  
  21.             margin: 0;  
  22.             padding: 0;  
  23.         }  
  24.     </style>  
  25. </head>  
  26. <body>  
  27.     <form id="form1" runat="server">  
  28.         <div>  
  29.             <asp:ScriptManager ID="ScriptManager1" runat="server">  
  30.             </asp:ScriptManager>  
  31.             <br />  
  32.             <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick">  
  33.             </asp:Timer>  
  34.             <br />  
  35.             <asp:UpdatePanel ID="BannerPanel" runat="server" UpdateMode="Conditional">  
  36.                 <ContentTemplate>  
  37.                     <asp:Button ID="btnDisplay" runat="server" Text="Display " OnClick="btnDisplay_Click" />  
  38.                     <asp:Image CssClass="Image1" ID="Image1" runat="server" Style="width: 100%;" />  
  39.                 </ContentTemplate>  
  40.             </asp:UpdatePanel>  
  41.         </div>  
  42.     </form>  
  43. </body>  
  44. </html>  
Thanks 
Accepted
1
Photo of hema latha
NA 27 447 7y
Thanks for reply manav but the snippet is same code which i am trying. but i am getting scroll bars or part of image is lost.Try for .bmp files for which height and width are more than of the screen size/asp page.Plz try 
1
Photo of Manav Pandya
NA 7.1k 24.1k 7y
Hello 
 
I have implemented this demo in my system .
 
I got perfect output as you required 
 
Note : Image also take place in whole page i.e 100% width 
 
Find Following Snippet :
 
  1. protected void btnDisplay_Click(object sender, EventArgs e)  
  2.         {  
  3.             // I have stored image local path to String variable  
  4.   
  5.             string MyImage = "Images/" + "textToImage20180117144937.png";  
  6.               
  7.             // Getting complete Path of an local system  
  8.             string localstr = Server.MapPath(MyImage);  
  9.   
  10.             // Coversion of Bytes  
  11.             Byte[] bytes = File.ReadAllBytes(localstr);  
  12.   
  13.             // Creation of base64string format  
  14.             string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);  
  15.   
  16.             // Fianl Image URL  
  17.             Image1.ImageUrl = "data:image;base64," + base64String;  
  18.         }  
Thanks
 
All the best :)