?
Solved

Image manipulation in ASP.NET

Posted on 2004-08-16
2
Medium Priority
?
444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

752 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