Solved

Image manipulation in ASP.NET

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Async and await with MVC and Web Api 3 30
varchar (max) 5 28
How can I use this extension method? 8 36
JavaScript error 1 33
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now