Solved

image resizer

Posted on 2014-03-10
13
300 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now