Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

image resizer

Posted on 2014-03-10
13
Medium Priority
?
316 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

927 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