Solved

Image manipulation in ASP.NET

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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