Skip to content
Loading
Image to fit in asp page
Thanks 
+1
  • You can use LEADTOOLS Image Viewer SDK technology in your application.
    https://www.leadtools.com/sdk/display
    Here is some sample code:
    1. using (RasterCodecs codecs = new RasterCodecs)  
    2. {  
    3.     // Initialize the ImageViewer  
    4.     imageViewer = new ImageViewer  
    5.     {  
    6.         BackColor = Color.White,  
    7.         UseDpi = true,  
    8.         ViewHorizontalAlignment = ControlAlignment.Center,  
    9.         ViewVerticalAlignment = ControlAlignment.Center,  
    10.         Dock = DockStyle.Fill  
    11.     };  
    12.     Controls.Add(imageViewer);  
    13.     var panZoom = new ImageViewerPanZoomInteractiveMode();  
    14.     imageViewer.InteractiveModes.Add(panZoom);  
    15.     // Setting to always fit image to image viewer  
    16.     imageViewer.Zoom(ControlSizeMode.FitAlways, 1.0, imageViewer.DefaultZoomOrigin);  
    17.   
    18.     imageViewer.Image = codecs.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);  
    19. }  
    +1
  • 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
  • Manav Pandya
    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 :) 
    0