Solved

image resizer

Posted on 2014-03-10
13
307 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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 500 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

751 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