VB.net Photo Manipulation Software

I need to write some custom photo software. We are getting digital pictures of students in and need to save them to our ID production software.  The students are having a difficult time getting the sizing and proportions down so we need the software to do certain things.
Open the picture from different extensions.
Rotate the picture.
Zoom in/out
Lighten/Darken.
Move the part of the picture into a viewfinder.
Save the part of the photo inside the viewfinder as a .jpg

I started by converting the incoming photo to a bitmap then wrote my controls.
    Private Sub InitializeImage()
        Try
            bitmapimage = CType(Bitmap.FromFile(Files(FILENUMBER)), Bitmap)
            '' pbdigitalphotos.SizeMode = PictureBoxSizeMode.AutoSize
            pbdigitalphotos.Image = bitmapimage
        Catch ex As System.IO.FileNotFoundException
            MessageBox.Show("There was an error. Check the path to the bitmap.")
        End Try
    End Sub
 
The zoom seems to distort the image when i go in and out.
    Public Sub ZoomImage(ByRef ZoomValue As Double)
        bitmapimage = New Bitmap(bitmapimage, (bitmapimage.Width / ZoomValue), (bitmapimage.Height / ZoomValue))
        'Create a new graphics object based on the new image
        Dim converted As Graphics = Graphics.FromImage(bitmapimage)
        'Clean up the image
        converted.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
        converted.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor
        converted.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half
        converted.DrawImage(bitmapimage, 0, 0)
        pbdigitalphotos.Image = bitmapimage
    End Sub

 the Lighten/Darken just goes black or white.
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pbimagetosave.Paint
        Try
            Dim brt As Single = sbbrightness.Value / 100
            Dim image_attr As New Imaging.ImageAttributes
            Dim cm As Imaging.ColorMatrix = New Imaging.ColorMatrix(New Single()() _
                { _
                New Single() {1.0, 0.0, 0.0, 0.0, 0.0}, _
                New Single() {0.0, 1.0, 0.0, 0.0, 0.0}, _
                New Single() {0.0, 0.0, 1.0, 0.0, 0.0}, _
                New Single() {0.0, 0.0, 0.0, 1.0, 0.0}, _
                New Single() {brt, brt, brt, 1.0, 1.0}})
            Dim rect As Rectangle = _
                Rectangle.Round(pbimagetosave.Image.GetBounds(GraphicsUnit.Pixel))
            Dim wid As Integer = pbimagetosave.Image.Width
            Dim hgt As Integer = pbimagetosave.Image.Height

            image_attr.SetColorMatrix(cm)
            e.Graphics.DrawImage(pbimagetosave.Image, rect, 0, 0, wid, _
                hgt, GraphicsUnit.Pixel, image_attr)
        Catch
        End Try
    End Sub

I can't get the viewfinder to stay ontop of the picture. Using the rectangle draw.

Am i going about this the wrong way?  Is there a better way to do the picture changing subs?  Just dont want to continue if the basic are not sound.  Any help would be great.
MillkindAsked:
Who is Participating?
 
ArkCommented:
You can do all conversion inside PictureBox_paint:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With cboZoom
            .Items.Add(50)
            .Items.Add(75)
            .Items.Add(100)
            .Items.Add(125)
            .Items.Add(150)
            .Items.Add(200)
            .Items.Add(300)
            .Items.Add(400)
        End With
        With sbBrightness
            .Minimum = -100
            .Maximum = 100
        End With
        Reset()
    End Sub

    Private Sub Reset()
        cboZoom.SelectedIndex = 2
        sbBrightness.Value = 0
    End Sub

    Private Sub cmdLoadPhoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoadPhoto.Click
        Using ofd As New OpenFileDialog
            If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                Try
                    pbOriginal.Image = Nothing
                    Reset()
                    pbOriginal.Image = Bitmap.FromFile(ofd.FileName)
                    pbModified.Refresh()
                Catch ex As Exception
                    MsgBox(ex.Message, MsgBoxStyle.Critical)
                End Try
            End If
        End Using
    End Sub

    Private Sub sbBrightness_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles sbBrightness.ValueChanged
        pbModified.Refresh()
    End Sub

    Private Sub cboZoom_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboZoom.SelectedIndexChanged
        pbModified.Refresh()
    End Sub

    Private Sub pbModified_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pbModified.Paint
        If pbOriginal.Image Is Nothing Then
            Return
        End If
        Dim brt As Single = sbBrightness.Value / 100
        Dim zoom As Double = Integer.Parse(cboZoom.Text) / 100
        Dim cm As Imaging.ColorMatrix = New Imaging.ColorMatrix(New Single()() _
                                        {New Single() {1.0, 0.0, 0.0, 0.0, 0.0}, _
                                         New Single() {0.0, 1.0, 0.0, 0.0, 0.0}, _
                                         New Single() {0.0, 0.0, 1.0, 0.0, 0.0}, _
                                         New Single() {0.0, 0.0, 0.0, 1.0, 0.0}, _
                                         New Single() {brt, brt, brt, 1.0, 1.0}})
        Dim wid As Integer = pbOriginal.Image.Width
        Dim hgt As Integer = pbOriginal.Image.Height
        Dim image_attr As New Imaging.ImageAttributes
        Dim rect As Rectangle = New Rectangle(0, 0, wid * zoom, hgt * zoom)
        image_attr.SetColorMatrix(cm)
        e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
        e.Graphics.DrawImage(pbOriginal.Image, rect, 0, 0, wid, hgt, GraphicsUnit.Pixel, image_attr)
    End Sub
End Class

Open in new window

Form contains:
2 pictureboxes (pbOriginal,pbModified)
command button (cmdLoadPhoto)
combobox (cboZoom)
HScorllBar (sbBrightness)
0
 
MillkindAuthor Commented:
Wow that zoom and brightness are great.  Any idea how to get a viewfinder to always stay on top of the original image?
0
 
MillkindAuthor Commented:
Or is there a way to make it so that the veiwfinder could be dragged around the original image with the mouse?
0
 
MillkindAuthor Commented:
okay got the viewfinder done with staying on top and transparency am working on getting it to move around now.
0
 
MillkindAuthor Commented:
viewfinder movement is done.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.