Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

image resizer

Posted on 2014-03-10
13
Medium Priority
?
310 Views
Last Modified: 2014-03-11
I am looking for a free open source for image resize similiar to ImageProcess. for windows application. Please see attachment. I don't know how to rotate img if horizontal.
img.jpg
0
Comment
Question by:VBdotnet2005
[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
  • 6
  • 6
13 Comments
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39920456
Does ImageProcess work for you? It seems that it has a Rotate method.

Modifying their first example you can achieve what you want:
byte[] photoBytes = File.ReadAllBytes(file);
int quality = 70;
ImageFormat format = ImageFormat.Jpeg;
Size size = new Size(150, 0);

using (MemoryStream inStream = new MemoryStream(photoBytes))
{
    using (MemoryStream outStream = new MemoryStream())
    {
        using (ImageFactory imageFactory = new ImageFactory())
        {
            // Load, resize, set the format and quality and save an image.
            imageFactory.Load(inStream)
                        .Resize(size)
                        .Format(format)
                        .Quality(quality)
                        .Rotate
                        (
                            new ImageProcessor.Imaging.RotateLayer
                            (
                                imageFactory.Image.Width<imageFactory.Image.Height
                                ?90
                                :0
                            )
                        )
                        .Save(outStream);
        }

        // Do something with the stream.
    }
}

Open in new window


What i am actually doing, is Rotate anyway, but the angle would be either 0 or 90 depending on the Width and Height of the image in question.

Giannis
0
 

Author Comment

by:VBdotnet2005
ID: 39921145
jyparask,

I tried your code. Please see the attachments. It rotated, but not the way it suppose to be.
original.jpg
result.jpg
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39921184
My code was an example on the sample provided in their site. As you see, in the example they resize the image to a certain size.

I think that in your case, you could remove the

.Resize(size)

Open in new window


part of my code.

Giannis
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:VBdotnet2005
ID: 39921272
Original size is 167 kb. What really want to do it if the width size is over 600 pixes, resize the width to 600 pixeds. I am not sure of the height.
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39921312
I would like to see your code and an example of what should the result be in the image with the flower.
0
 

Author Comment

by:VBdotnet2005
ID: 39921450
This is what I have so far.

 Public Sub ResizeImg(ByVal filename As String)

        Dim photobytes As Byte() = File.ReadAllBytes(filename)
        Dim quality As Integer = 100
        Dim format As ImageFormat = ImageFormat.Jpeg
        Dim size_ As Size = New Size(150, 0)
        Dim rt As New RotateLayer

        Using inStream As New MemoryStream(photobytes)
            Using outStream As New MemoryStream()
                Using imageFactory As New ImageFactory()
                    Dim test = imageFactory.Load(inStream)
                    imageFactory.Load(inStream) _
                        .Rotate(New ImageProcessor.Imaging.RotateLayer(If(imageFactory.Image.Width < imageFactory.Image.Height, 90, 0))) _
                        .Save("C:\original.jpg")
                End Using
            End Using
        End Using
    End Sub

Open in new window

0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39921477
Try This:


 Public Sub ResizeImg(ByVal filename As String)

        Dim photobytes As Byte() = File.ReadAllBytes(filename)
        Dim quality As Integer = 100
        Dim format As ImageFormat = ImageFormat.Jpeg
        Dim size_ As Size = New Size(600, 0)
        Dim rt As New RotateLayer

        Using inStream As New MemoryStream(photobytes)
            Using outStream As New MemoryStream()
                Using imageFactory As New ImageFactory()
                    Dim test = imageFactory.Load(inStream)
                    imageFactory.Load(inStream) _
                        .Resize(If(imageFactory.Image.Width>600,size,imageFactory.Image.Size))
                        .Rotate(New ImageProcessor.Imaging.RotateLayer(If(imageFactory.Image.Width < imageFactory.Image.Height, 90, 0))) _
                        .Save("C:\original.jpg")
                End Using
            End Using
        End Using
    End Sub
                                            

Open in new window


So, if the width is bigger than 600, it will reduce it to 600.

Giannis
0
 

Author Comment

by:VBdotnet2005
ID: 39921637
I tried your code. Please see attachments.
vertical.jpg
result.jpg
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39921655
Ok, can you plz send what the result should be in that case?
0
 

Author Comment

by:VBdotnet2005
ID: 39921677
It should be like this. It should be rotated.
result.jpg
0
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 2000 total points
ID: 39921695
So, you just need resizing, am i correct?

 Public Sub ResizeImg(ByVal filename As String)

        Dim photobytes As Byte() = File.ReadAllBytes(filename)
        Dim quality As Integer = 100
        Dim format As ImageFormat = ImageFormat.Jpeg
        Dim size_ As Size = New Size(600, 0)
        Dim rt As New RotateLayer

        Using inStream As New MemoryStream(photobytes)
            Using outStream As New MemoryStream()
                Using imageFactory As New ImageFactory()
                    Dim test = imageFactory.Load(inStream)
                    imageFactory.Load(inStream) _
                        .Resize(If(imageFactory.Image.Width>600,size,imageFactory.Image.Size)) _
                        .Save("C:\original.jpg")
                End Using
            End Using
        End Using
    End Sub

Open in new window

0
 

Author Comment

by:VBdotnet2005
ID: 39922308
Thank you for your help.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

660 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