How to get image in specified size given in parameter?

Shell

I want to display image in specified size given in parameter like this http://i.stack.imgur.com/zOQ8r.jpg?s=128&g=1 .

Suppose my image1.jpg is in image folder like this http://example.com/images/image1.jpg then if I specify the parameter like ?s=200 then image should be resized to 200x200 size and display without any other element except <img> tag.

I am not asking about code and example. I just need a logic or an idea. B'Coz, I am completely blank about it. Even I don't know what should I search on google. I am new in Web Application Development.

I want just same as http://lorempizza.com/ developed by rlemon

Plz give some ideas about it. Any help will be appreciated

Thanks & Regards

Monah

you can use the following function to re-size the image

public Image ImageResize(Image image, int width, int height)
{
     Bitmap newImage = new Bitmap(width, height);
     using (Graphics gr = Graphics.FromImage(newImage))
     {
            gr.SmoothingMode = SmoothingMode.AntiAlias;
            gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
            gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
            gr.DrawImage(image, new Rectangle(0, 0, width, height));
     }
     return newImage as Image;
}

and to display the image

1- use the asp image tag

<asp:Image id="imageTag" runat="server"/>

2- save the Image to a folder by the following Image temp=ImageResize(YourImage,200,200);

temp.SaveAs(MapPath("~/Images/image1.png"));

3- map the image url to the path

imageTag.ImageUrl=Server.MapPath("~/Images/image1.png");

another approach, is to use the ashx handler if you insist to use <img>, but at the end , asp:Image will be rendered as <img>

Edited Here

how to get the image resized using ashx

1- create a generic handler and name it ImageHandler

 public class ImageHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            var directory = @"Location of the images" // example c:\Data;
            var path = context.Request.QueryString["path"];
            var size = Convert.ToInt32(context.Request.QueryString["size"]);
            var image = Image.FromFile(string.Format(@"{0}\{1}.png", directory, path));
            image = ImageResize(image, size, size);
            context.Response.ContentType = "image/png";
            context.Response.BinaryWrite(ImageToByte(image));
        }

        public Image ImageResize(Image image, int width, int height)
        {
            Bitmap newImage = new Bitmap(width, height);
            using (Graphics gr = Graphics.FromImage(newImage))
            {
                gr.SmoothingMode = SmoothingMode.AntiAlias;
                gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
                gr.DrawImage(image, new Rectangle(0, 0, width, height));
            }
            return newImage as Image;
        }

        public byte[] ImageToByte(Image img)
        {
            byte[] byteArray = new byte[0];
            using (MemoryStream stream = new MemoryStream())
            {
                img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                stream.Close();

                byteArray = stream.ToArray();
            }
            return byteArray;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

2- in the aspx page, use the following

<img src="~/ImageHandler.ashx?path=NameOfImage&size=SizeOfImage" runat="server" />

hope this will help you

regards

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to get and print values properly form a given URL parameter

분류에서Dev

Reducing an image byte size to given value for format other than jpeg

분류에서Dev

How to create a two dimensional array of given size in C++

분류에서Dev

How do I force a tmux window to be a given size

분류에서Dev

How to set the background image according to screen size?

분류에서Dev

How to get Google Directions to stay on a specified route to get somewhere?

분류에서Dev

Facebook Graph API: get the full-size poster image for a video

분류에서Dev

How to view raw binary data as an image with given width and height?

분류에서Dev

How to get file size in hex format?

분류에서Dev

How do I get the specified node from XML in SQL

분류에서Dev

Delphi How to parse specified values from HTTP get

분류에서Dev

How can the, encrypted with AES, and BASE64 encoded, SSH private key, have size smaller than specified?

분류에서Dev

How to get parameter with routing rules in CodeIgniter

분류에서Dev

@WebParam on a parameter of interface method - how to get name?

분류에서Dev

How to Get Equivalent parameter to `mkdir -p` for `mount`?

분류에서Dev

How to get @interface parameter in jersey WriterInterceptor Implementation

분류에서Dev

How to render an action plus GET parameter?

분류에서Dev

How to update a get parameter in a url with jquery

분류에서Dev

Given Date parameter is considered as Date Time parameter

분류에서Dev

How to find the max image size supported for contacts images?

분류에서Dev

java Android - how can I keep Image's actual size?

분류에서Dev

How choose image size for adding own Overlay in google map api?

분류에서Dev

how to hide image when screen size 600px

분류에서Dev

How Can I re-size an image in VB.Net

분류에서Dev

Delphi, TTreeView: how to get the screen coordinates of the given node and its icon?

분류에서Dev

Given a DayOfTheWeek how do i get the date from an existing datetime

분류에서Dev

How to get the closest ul element to the given css offset using jquery

분류에서Dev

how to get the actual time format given in the javascript date object

분류에서Dev

How to place a Rectangle in a new image with different size, while preserving the size and quality of the orignial Rectangle?

Related 관련 기사

  1. 1

    How to get and print values properly form a given URL parameter

  2. 2

    Reducing an image byte size to given value for format other than jpeg

  3. 3

    How to create a two dimensional array of given size in C++

  4. 4

    How do I force a tmux window to be a given size

  5. 5

    How to set the background image according to screen size?

  6. 6

    How to get Google Directions to stay on a specified route to get somewhere?

  7. 7

    Facebook Graph API: get the full-size poster image for a video

  8. 8

    How to view raw binary data as an image with given width and height?

  9. 9

    How to get file size in hex format?

  10. 10

    How do I get the specified node from XML in SQL

  11. 11

    Delphi How to parse specified values from HTTP get

  12. 12

    How can the, encrypted with AES, and BASE64 encoded, SSH private key, have size smaller than specified?

  13. 13

    How to get parameter with routing rules in CodeIgniter

  14. 14

    @WebParam on a parameter of interface method - how to get name?

  15. 15

    How to Get Equivalent parameter to `mkdir -p` for `mount`?

  16. 16

    How to get @interface parameter in jersey WriterInterceptor Implementation

  17. 17

    How to render an action plus GET parameter?

  18. 18

    How to update a get parameter in a url with jquery

  19. 19

    Given Date parameter is considered as Date Time parameter

  20. 20

    How to find the max image size supported for contacts images?

  21. 21

    java Android - how can I keep Image's actual size?

  22. 22

    How choose image size for adding own Overlay in google map api?

  23. 23

    how to hide image when screen size 600px

  24. 24

    How Can I re-size an image in VB.Net

  25. 25

    Delphi, TTreeView: how to get the screen coordinates of the given node and its icon?

  26. 26

    Given a DayOfTheWeek how do i get the date from an existing datetime

  27. 27

    How to get the closest ul element to the given css offset using jquery

  28. 28

    how to get the actual time format given in the javascript date object

  29. 29

    How to place a Rectangle in a new image with different size, while preserving the size and quality of the orignial Rectangle?

뜨겁다태그

보관