Solved

image resizer

Posted on 2014-03-10
13
308 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

615 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