?
Solved

Image manipulation in ASP.NET

Posted on 2004-08-16
2
Medium Priority
?
452 Views
Last Modified: 2006-11-17
I want to slice up GIF images by specifying a set of pixel coordinates and saving the referenced portion of the image to a new GIF file. How do I do this?
0
Comment
Question by:crescendo
2 Comments
 
LVL 21

Accepted Solution

by:
tovvenki earned 1000 total points
ID: 11817830
Hi,
check whether the following paq helps you
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20664097.html?query=cut+image+&clearTAFilter=true
the accepted solution from xls is
// System.Drawing;

Bitmap original = new Image("file.jpg");
Bitmap newBitmap= new Bitmap(1024,768, PixelFormatFlags32Argb);
newBitmap.DrawImage()... // use any of the methods that you like..
newBitmap.Save("cutimage.jpg");

Hope that this helps you

regards,
venki
0
 
LVL 9

Author Comment

by:crescendo
ID: 11818924
Thanks, venki.

It gave me enough to understand how to do what I wanted. If anyone is interested, the code below takes an image and creates a sliced image. The Slice function does this, allowing you to specify the coordonates and dimensions of the slice. The Button1 click routine at the bottom calls Slice and saves and displays the result.

A word of caution, the colours in the slice differ slightly from the orginal, they look dithered, and I'm looking into this.

- crescendo


    Private Function Slice(ByVal imgPhoto As Image, ByVal FromX As Integer, ByVal FromY As Integer, _
    ByVal nWidth As Integer, ByVal nHeight As Integer) As Image

        Dim bmPhoto As Bitmap = New Bitmap(nWidth, nHeight, PixelFormat.Format24bppRgb)
        bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)

        Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
        grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic

        Dim rectSlice As Rectangle = New Rectangle
        rectSlice.X = FromX
        rectSlice.Y = FromY
        rectSlice.Height = nHeight
        rectSlice.Width = nWidth

        grPhoto.DrawImage(imgPhoto, 0, 0, rectSlice, GraphicsUnit.Pixel)
        grPhoto.Dispose()
        Return bmPhoto

    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim WorkingDirectory As String = Server.MapPath("images/test") + "\"
        Dim imgPhoto As Image = Image.FromFile(WorkingDirectory + "bluecallout.gif")
        Dim imgSlice As Image = Slice(imgPhoto, 0, 0, 150, 40)
        imgSlice.Save(WorkingDirectory + "top.gif", ImageFormat.Gif)

        imgTop.ImageUrl = "images/test/top.gif"
    End Sub
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question