?
Solved

VB.net Photo Manipulation Software

Posted on 2012-09-10
5
Medium Priority
?
432 Views
Last Modified: 2012-09-13
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.
0
Comment
Question by:Millkind
  • 4
5 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 38385638
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
 

Author Comment

by:Millkind
ID: 38387061
Wow that zoom and brightness are great.  Any idea how to get a viewfinder to always stay on top of the original image?
0
 

Author Comment

by:Millkind
ID: 38387171
Or is there a way to make it so that the veiwfinder could be dragged around the original image with the mouse?
0
 

Author Comment

by:Millkind
ID: 38387378
okay got the viewfinder done with staying on top and transparency am working on getting it to move around now.
0
 

Author Comment

by:Millkind
ID: 38387702
viewfinder movement is done.
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Integration Management Part 2
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

839 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