Solved

Image manipulation in ASP.NET

Posted on 2004-08-16
2
424 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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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 …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 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