onyak
asked on
Draw an image from mouse-down & drag corrdinates on existing picturebox
I need to be able to zoom in on an image in a PictureBox by using the users set corrdinates using the mouse down and mouse up events. This is my existing code that does not work. I need this as soon as possible, it's setting me back on my project.
'on mouse down gets the x,y position of the mouse
Public Sub mDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles picImage.MouseDown
'Checks if left mouse button in clicked
If e.Button <> MouseButtons.Left Then
Exit Sub
Else
'Gets starting position of the mouse
startX = e.X
startY = e.Y
down = New Point(startX, startY)
End If
End Sub
'on mouse up gets the x,y position of the mouse and draws user defined
'rectangle. Then saves the page as curF & "s" & ".tif"
Private Sub mUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles picImage.MouseUp
'objNewBmp.Dispose()
Dim img As Drawing.Image
'sets the current page as image.
img = Drawing.Image.FromFile(str Path & curF & ".tif")
Dim objBmp As New Bitmap(img, img.Width, img.Height)
Dim objNewBmp As New Bitmap(objBmp.Width, objBmp.Height, Imaging.PixelFormat.Format 16bppRgb55 5)
Dim g As Graphics
g = Graphics.FromImage(objNewB mp)
'Creats a duplicate image file as bitmap format
Dim rect As Rectangle
With rect
.Width = img.Width
.Height = img.Height
.X = 0
.Y = 0
End With
g.DrawImage(img, rect)
Dim DrawRect As Rectangle
'Sets the position of the mouse
finishX = e.X
finishY = e.Y
up = New Point(finishX, finishY)
'Sets the value of rectangle, x, y, width, height position
DrawRect = New Rectangle(Math.Min(up.X, down.X), Math.Min(up.Y, down.Y), Math.Abs(up.X - down.X), Math.Abs(up.Y - down.Y))
Dim myGraphics As Graphics
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(picImage .Handle)
myGraphics.DrawImage(img, rect, DrawRect, GraphicsUnit.Pixel)
'Dim b As SolidBrush = New SolidBrush(Color.White)
'g.FillRectangle(b, DrawRect)
''Creates an rectagnle on the picture box for visual.
'g = picImage.CreateGraphics
'g.FillRectangle(b, DrawRect)
g.Dispose()
objNewBmp.Dispose()
End Sub
'on mouse down gets the x,y position of the mouse
Public Sub mDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse
'Checks if left mouse button in clicked
If e.Button <> MouseButtons.Left Then
Exit Sub
Else
'Gets starting position of the mouse
startX = e.X
startY = e.Y
down = New Point(startX, startY)
End If
End Sub
'on mouse up gets the x,y position of the mouse and draws user defined
'rectangle. Then saves the page as curF & "s" & ".tif"
Private Sub mUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse
'objNewBmp.Dispose()
Dim img As Drawing.Image
'sets the current page as image.
img = Drawing.Image.FromFile(str
Dim objBmp As New Bitmap(img, img.Width, img.Height)
Dim objNewBmp As New Bitmap(objBmp.Width, objBmp.Height, Imaging.PixelFormat.Format
Dim g As Graphics
g = Graphics.FromImage(objNewB
'Creats a duplicate image file as bitmap format
Dim rect As Rectangle
With rect
.Width = img.Width
.Height = img.Height
.X = 0
.Y = 0
End With
g.DrawImage(img, rect)
Dim DrawRect As Rectangle
'Sets the position of the mouse
finishX = e.X
finishY = e.Y
up = New Point(finishX, finishY)
'Sets the value of rectangle, x, y, width, height position
DrawRect = New Rectangle(Math.Min(up.X, down.X), Math.Min(up.Y, down.Y), Math.Abs(up.X - down.X), Math.Abs(up.Y - down.Y))
Dim myGraphics As Graphics
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(picImage
myGraphics.DrawImage(img, rect, DrawRect, GraphicsUnit.Pixel)
'Dim b As SolidBrush = New SolidBrush(Color.White)
'g.FillRectangle(b, DrawRect)
''Creates an rectagnle on the picture box for visual.
'g = picImage.CreateGraphics
'g.FillRectangle(b, DrawRect)
g.Dispose()
objNewBmp.Dispose()
End Sub
This code works just fine for me... what seems to be the issue you're having?
ASKER
The image does change, but it doesn't do what I need it to do. I need to crop out what the user selects via mouse-down and mouse-up. Then display the cropped part of the image in the picturebox.
Again, this seems to work. Are you clicking-and-dragging, or trying to click twice?
ASKER
I commented out...
g.Dispose()
objNewBmp.Dispose()
At the bottom of the code. Now I zooms, but it's not accurate. Can you send me all of the code your using?
g.Dispose()
objNewBmp.Dispose()
At the bottom of the code. Now I zooms, but it's not accurate. Can you send me all of the code your using?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I took your code and created a new project with it. It did zoom, but it was not exact. There must be something else in the way. Check out all the code from my form...
Imports System.Drawing.Imaging
Imports System.IO.File
Public Class frmAeroTiffEditor
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents GroupBox As System.Windows.Forms.Group Box
Friend WithEvents btnClose As System.Windows.Forms.Butto n
Friend WithEvents cboFrameNo As System.Windows.Forms.Combo Box
Friend WithEvents btnOpen As System.Windows.Forms.Butto n
Friend WithEvents btnPrint As System.Windows.Forms.Butto n
Friend WithEvents btnUnZoom As System.Windows.Forms.Butto n
Friend WithEvents btnZoom As System.Windows.Forms.Butto n
Friend WithEvents btnPrevious As System.Windows.Forms.Butto n
Friend WithEvents btnNext As System.Windows.Forms.Butto n
Friend WithEvents btnSave As System.Windows.Forms.Butto n
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveF ileDialog
Friend WithEvents MainMenu1 As System.Windows.Forms.MainM enu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem10 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem12 As System.Windows.Forms.MenuI tem
Friend WithEvents ToolTip As System.Windows.Forms.ToolT ip
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenF ileDialog
Friend WithEvents picImage As System.Windows.Forms.Pictu reBox
Friend WithEvents lbl1 As System.Windows.Forms.Label
Friend WithEvents lbl2 As System.Windows.Forms.Label
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Cont ainer
Dim resources As System.Resources.ResourceM anager = New System.Resources.ResourceM anager(Get Type(frmAe roTiffEdit or))
Me.GroupBox = New System.Windows.Forms.Group Box
Me.lbl2 = New System.Windows.Forms.Label
Me.lbl1 = New System.Windows.Forms.Label
Me.btnClose = New System.Windows.Forms.Butto n
Me.cboFrameNo = New System.Windows.Forms.Combo Box
Me.btnOpen = New System.Windows.Forms.Butto n
Me.btnPrint = New System.Windows.Forms.Butto n
Me.btnUnZoom = New System.Windows.Forms.Butto n
Me.btnZoom = New System.Windows.Forms.Butto n
Me.btnPrevious = New System.Windows.Forms.Butto n
Me.btnNext = New System.Windows.Forms.Butto n
Me.btnSave = New System.Windows.Forms.Butto n
Me.SaveFileDialog1 = New System.Windows.Forms.SaveF ileDialog
Me.MainMenu1 = New System.Windows.Forms.MainM enu
Me.MenuItem1 = New System.Windows.Forms.MenuI tem
Me.MenuItem2 = New System.Windows.Forms.MenuI tem
Me.MenuItem3 = New System.Windows.Forms.MenuI tem
Me.MenuItem4 = New System.Windows.Forms.MenuI tem
Me.MenuItem6 = New System.Windows.Forms.MenuI tem
Me.MenuItem7 = New System.Windows.Forms.MenuI tem
Me.MenuItem9 = New System.Windows.Forms.MenuI tem
Me.MenuItem8 = New System.Windows.Forms.MenuI tem
Me.MenuItem10 = New System.Windows.Forms.MenuI tem
Me.MenuItem12 = New System.Windows.Forms.MenuI tem
Me.ToolTip = New System.Windows.Forms.ToolT ip(Me.comp onents)
Me.OpenFileDialog1 = New System.Windows.Forms.OpenF ileDialog
Me.picImage = New System.Windows.Forms.Pictu reBox
Me.GroupBox.SuspendLayout( )
Me.SuspendLayout()
'
'GroupBox
'
Me.GroupBox.Controls.Add(M e.lbl2)
Me.GroupBox.Controls.Add(M e.lbl1)
Me.GroupBox.Controls.Add(M e.btnClose )
Me.GroupBox.Controls.Add(M e.cboFrame No)
Me.GroupBox.Controls.Add(M e.btnOpen)
Me.GroupBox.Controls.Add(M e.btnPrint )
Me.GroupBox.Controls.Add(M e.btnUnZoo m)
Me.GroupBox.Controls.Add(M e.btnZoom)
Me.GroupBox.Controls.Add(M e.btnPrevi ous)
Me.GroupBox.Controls.Add(M e.btnNext)
Me.GroupBox.Controls.Add(M e.btnSave)
Me.GroupBox.Location = New System.Drawing.Point(3, -1)
Me.GroupBox.Name = "GroupBox"
Me.GroupBox.Size = New System.Drawing.Size(608, 32)
Me.GroupBox.TabIndex = 25
Me.GroupBox.TabStop = False
'
'lbl2
'
Me.lbl2.Location = New System.Drawing.Point(472, 8)
Me.lbl2.Name = "lbl2"
Me.lbl2.Size = New System.Drawing.Size(72, 16)
Me.lbl2.TabIndex = 37
'
'lbl1
'
Me.lbl1.Location = New System.Drawing.Point(392, 8)
Me.lbl1.Name = "lbl1"
Me.lbl1.Size = New System.Drawing.Size(72, 16)
Me.lbl1.TabIndex = 36
'
'btnClose
'
Me.btnClose.Image = CType(resources.GetObject( "btnClose. Image"), System.Drawing.Image)
Me.btnClose.Location = New System.Drawing.Point(64, 8)
Me.btnClose.Name = "btnClose"
Me.btnClose.Size = New System.Drawing.Size(32, 24)
Me.btnClose.TabIndex = 35
Me.ToolTip.SetToolTip(Me.b tnClose, "Close Image")
'
'cboFrameNo
'
Me.cboFrameNo.Location = New System.Drawing.Point(192, 8)
Me.cboFrameNo.Name = "cboFrameNo"
Me.cboFrameNo.Size = New System.Drawing.Size(48, 19)
Me.cboFrameNo.TabIndex = 34
'
'btnOpen
'
Me.btnOpen.Image = CType(resources.GetObject( "btnOpen.I mage"), System.Drawing.Image)
Me.btnOpen.Location = New System.Drawing.Point(0, 8)
Me.btnOpen.Name = "btnOpen"
Me.btnOpen.Size = New System.Drawing.Size(32, 24)
Me.btnOpen.TabIndex = 27
'
'btnPrint
'
Me.btnPrint.Image = CType(resources.GetObject( "btnPrint. Image"), System.Drawing.Image)
Me.btnPrint.Location = New System.Drawing.Point(96, 8)
Me.btnPrint.Name = "btnPrint"
Me.btnPrint.Size = New System.Drawing.Size(32, 24)
Me.btnPrint.TabIndex = 26
'
'btnUnZoom
'
Me.btnUnZoom.Image = CType(resources.GetObject( "btnUnZoom .Image"), System.Drawing.Image)
Me.btnUnZoom.Location = New System.Drawing.Point(304, 8)
Me.btnUnZoom.Name = "btnUnZoom"
Me.btnUnZoom.Size = New System.Drawing.Size(32, 24)
Me.btnUnZoom.TabIndex = 24
'
'btnZoom
'
Me.btnZoom.Image = CType(resources.GetObject( "btnZoom.I mage"), System.Drawing.Image)
Me.btnZoom.Location = New System.Drawing.Point(336, 8)
Me.btnZoom.Name = "btnZoom"
Me.btnZoom.Size = New System.Drawing.Size(32, 24)
Me.btnZoom.TabIndex = 23
'
'btnPrevious
'
Me.btnPrevious.Image = CType(resources.GetObject( "btnPrevio us.Image") , System.Drawing.Image)
Me.btnPrevious.Location = New System.Drawing.Point(160, 8)
Me.btnPrevious.Name = "btnPrevious"
Me.btnPrevious.Size = New System.Drawing.Size(32, 24)
Me.btnPrevious.TabIndex = 22
'
'btnNext
'
Me.btnNext.Image = CType(resources.GetObject( "btnNext.I mage"), System.Drawing.Image)
Me.btnNext.Location = New System.Drawing.Point(240, 8)
Me.btnNext.Name = "btnNext"
Me.btnNext.Size = New System.Drawing.Size(32, 24)
Me.btnNext.TabIndex = 21
'
'btnSave
'
Me.btnSave.Image = CType(resources.GetObject( "btnSave.I mage"), System.Drawing.Image)
Me.btnSave.Location = New System.Drawing.Point(32, 8)
Me.btnSave.Name = "btnSave"
Me.btnSave.Size = New System.Drawing.Size(32, 24)
Me.btnSave.TabIndex = 20
Me.ToolTip.SetToolTip(Me.b tnSave, "Save File")
'
'SaveFileDialog1
'
Me.SaveFileDialog1.FileNam e = "doc1"
'
'MainMenu1
'
Me.MainMenu1.MenuItems.Add Range(New System.Windows.Forms.MenuI tem() {Me.MenuItem1, Me.MenuItem7, Me.MenuItem10})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.Add Range(New System.Windows.Forms.MenuI tem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem6})
Me.MenuItem1.Text = "File"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Shortcut = System.Windows.Forms.Short cut.CtrlO
Me.MenuItem2.Text = "Open"
'
'MenuItem3
'
Me.MenuItem3.Index = 1
Me.MenuItem3.Shortcut = System.Windows.Forms.Short cut.CtrlS
Me.MenuItem3.Text = "Save"
'
'MenuItem4
'
Me.MenuItem4.Index = 2
Me.MenuItem4.Shortcut = System.Windows.Forms.Short cut.CtrlC
Me.MenuItem4.Text = "Close"
'
'MenuItem6
'
Me.MenuItem6.Index = 3
Me.MenuItem6.Shortcut = System.Windows.Forms.Short cut.CtrlX
Me.MenuItem6.Text = "Exit"
'
'MenuItem7
'
Me.MenuItem7.Index = 1
Me.MenuItem7.MenuItems.Add Range(New System.Windows.Forms.MenuI tem() {Me.MenuItem9, Me.MenuItem8})
Me.MenuItem7.Text = "Toolbar"
'
'MenuItem9
'
Me.MenuItem9.Index = 0
Me.MenuItem9.Text = "Show"
'
'MenuItem8
'
Me.MenuItem8.Index = 1
Me.MenuItem8.Text = "Hide"
'
'MenuItem10
'
Me.MenuItem10.Index = 2
Me.MenuItem10.MenuItems.Ad dRange(New System.Windows.Forms.MenuI tem() {Me.MenuItem12})
Me.MenuItem10.Text = "Help"
'
'MenuItem12
'
Me.MenuItem12.Index = 0
Me.MenuItem12.Text = "About"
'
'ToolTip
'
Me.ToolTip.ShowAlways = True
'
'picImage
'
Me.picImage.Anchor = CType((((System.Windows.Fo rms.Anchor Styles.Top Or System.Windows.Forms.Ancho rStyles.Bo ttom) _
Or System.Windows.Forms.Ancho rStyles.Le ft) _
Or System.Windows.Forms.Ancho rStyles.Ri ght), System.Windows.Forms.Ancho rStyles)
Me.picImage.BackColor = System.Drawing.Color.Gains boro
Me.picImage.Cursor = System.Windows.Forms.Curso rs.Cross
Me.picImage.Location = New System.Drawing.Point(8, 40)
Me.picImage.Name = "picImage"
Me.picImage.Size = New System.Drawing.Size(603, 639)
Me.picImage.TabIndex = 24
Me.picImage.TabStop = False
'
'frmAeroTiffEditor
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 13)
Me.AutoScroll = True
Me.ClientSize = New System.Drawing.Size(614, 679)
Me.Controls.Add(Me.GroupBo x)
Me.Controls.Add(Me.picImag e)
Me.Font = New System.Drawing.Font("Batan g", 8.25!, System.Drawing.FontStyle.R egular, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.Icon = CType(resources.GetObject( "$this.Ico n"), System.Drawing.Icon)
Me.Name = "frmAeroTiffEditor"
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormS tartPositi on.CenterP arent
Me.Text = "AeroControlex Tiff Viewer"
Me.GroupBox.ResumeLayout(F alse)
Me.ResumeLayout(False)
End Sub
#End Region
Dim curF As Integer
Dim finishX, finishY As Integer
Dim startX, startY As Integer
Dim up, down As Point
Dim strFilePath As String
Dim strPath As String
Dim strFileName As String
Dim g As Graphics
Dim totFrame As Integer
Dim frameCount As String
Dim pageNo As Integer
Dim objfile As System.IO.File
Dim objImage As System.Drawing.Image
Dim ifSaved As Boolean = False
Dim isDelete As Boolean = False
Dim isEdit As Boolean = False
Private _instance As String = 1
Public Property InstanceName() As String
Get
Return _instance
End Get
Set(ByVal Value As String)
_instance = Value
End Set
End Property
'Loads the .Tiff file and saves every frame as a seperate .tiff file
Public Sub loadImage(ByVal strFilePath As String, ByVal ImageCaption As String)
picBoxSize()
ifSaved = False
cboFrameNo.Items.Clear()
'Changed the cursor to waitCursor
Me.Cursor = System.Windows.Forms.Curso rs.WaitCur sor
'Sets the tiff file as an image object.
objImage = objImage.FromFile(strFileP ath)
Dim objGuid As Guid = (objImage.FrameDimensionsL ist(0))
Dim objDimension As System.Drawing.Imaging.Fra meDimensio n = New System.Drawing.Imaging.Fra meDimensio n(objGuid)
'Gets the total number of frames in the .tiff file
totFrame = objImage.GetFrameCount(obj Dimension)
'Adds number of frames to the combo box for displaying purposes.
Dim i As Integer
For i = 0 To totFrame - 1
cboFrameNo.Items.Add(i)
Next
cboFrameNo.Items.IndexOf(1 )
'Sets the temporary folder to "C:\temp\"
strPath = "c:\temp\" & _instance
'Saves every frame as a seperate file.
Dim z As Integer
z = 0
curF = 0
For z = 0 To (totFrame - 1)
objImage.SelectActiveFrame (objDimens ion, curF)
objImage.Save(strPath & curF & ".tif", Imaging.ImageFormat.Tiff)
curF = curF + 1
Next
curF = 0
'set window caption
Me.Text = ImageCaption
'Displayes the frames
DisplayFrame()
Me.Cursor = System.Windows.Forms.Curso rs.Default
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Sets the tooltip text's
ToolTip.SetToolTip(btnOpen , "Open Image")
ToolTip.SetToolTip(btnSave , "Copy to")
ToolTip.SetToolTip(btnPrin t, "Print to PDF")
ToolTip.SetToolTip(btnPrev ious, "Previous Page")
ToolTip.SetToolTip(btnNext , "Next Page")
ToolTip.SetToolTip(cboFram eNo, "Current Page")
ToolTip.SetToolTip(btnUnZo om, "UnZoom by 1.25%")
ToolTip.SetToolTip(btnZoom , "Zoom by 1.25%")
curF = 0
End Sub
'on click displays the next page
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If checkPath() = True Then
btnPrevious.Enabled = True
If isEdit = True Then
isDelete = False
Else
isDelete = True
End If
nextFrame()
DisplayFrame()
Else
Exit Sub
End If
End Sub
'Gets the next frame number
Private Sub nextFrame()
If curF = totFrame - 1 Then
btnNext.Enabled = False
Exit Sub
Else
curF = curF + 1
End If
End Sub
'on click displays the previous frame
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
If checkPath() = True Then
btnNext.Enabled = True
If isEdit = True Then
isDelete = False
Else
isDelete = True
End If
previousFrame()
DisplayFrame()
Else
Exit Sub
End If
End Sub
'gets the previous frame number
Public Sub previousFrame()
If curF = 0 Then
btnPrevious.Enabled = False
Exit Sub
Else
curF = curF - 1
End If
End Sub
'Displays the selected frame
Private Sub DisplayFrame()
'if isDelete is true sets the image as the original .tiff image
'if inDelete is false sets the imahe as seperate file from the temp folder
Select Case isDelete
Case True
Dim objImage As System.Drawing.Image = objImage.FromFile(strFileP ath)
Case False
Dim objImage As System.Drawing.Image = objImage.FromFile(strPath & curF & ".tif")
strFilePath = strPath & curF & ".tif"
End Select
Dim objGuid As Guid = (objImage.FrameDimensionsL ist(0))
Dim objDimension As System.Drawing.Imaging.Fra meDimensio n = New System.Drawing.Imaging.Fra meDimensio n(objGuid)
objImage.SelectActiveFrame (objDimens ion, curF)
picImage.Image = objImage
picImage.SizeMode = PictureBoxSizeMode.Stretch Image
cboFrameNo.Text = curF
End Sub
'Gets the selected frame number for display from combo box
Private Sub cboFrameNo_SelectedIndexCh anged(ByVa l sender As System.Object, ByVal e As System.EventArgs) Handles cboFrameNo.SelectedIndexCh anged
curF = cboFrameNo.Text
If curF = totFrame - 1 Then
btnNext.Enabled = True
Exit Sub
Else
DisplayFrame()
End If
End Sub
'on click zooms the image by 1.25 %
Private Sub btnZoom_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoom.Click
If checkPath() = True Then
picImage.Width = CInt(picImage.Width * 1.25)
picImage.Height = CInt(picImage.Height * 1.25)
Else
Exit Sub
End If
End Sub
'on click unzooms the image by 1.25%
Private Sub btnUnZoom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnZoom.Click
If checkPath() = True Then
picImage.Width = CInt(picImage.Width / 1.25)
picImage.Height = CInt(picImage.Height / 1.25)
Else
Exit Sub
End If
End Sub
'Gets the ctual size of the image
Private Sub actualSize()
picImage.Width = objImage.Width
picImage.Height = objImage.Height
End Sub
Private Sub picBoxSize()
picImage.Width = 600
picImage.Height = 640
End Sub
'Gets the cross cursor
Private Sub btnErase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If checkPath() = True Then
MsgBox("Screen will change to Edit Mode", MsgBoxStyle.Critical)
Me.Cursor = System.Windows.Forms.Curso rs.Cross
isEdit = True
isDelete = False
actualSize()
DisplayFrame()
Else
Exit Sub
End If
End Sub
'on mouse down gets the x,y position of the mouse
Public Sub mDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles picImage.MouseDown
'Checks if left mouse button in clicked
If e.Button <> MouseButtons.Left Then
Exit Sub
Else
'Gets starting position of the mouse
startX = e.X
startY = e.Y
down = New Point(startX, startY)
End If
End Sub
'on mouse up gets the x,y position of the mouse and draws user defined
'rectangle. Then saves the page as curF & "s" & ".tif"
Private Sub mUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles picImage.MouseUp
'objNewBmp.Dispose()
Dim img As Drawing.Image
'sets the current page as image.
img = picImage.Image
Dim objBmp As New Bitmap(img, img.Width, img.Height)
Dim objNewBmp As New Bitmap(objBmp.Width, objBmp.Height, Imaging.PixelFormat.Format 16bppRgb55 5)
Dim g As Graphics
g = Graphics.FromImage(objNewB mp)
'Creats a duplicate image file as bitmap format
Dim rect As Rectangle
With rect
.Width = img.Width
.Height = img.Height
.X = 0
.Y = 0
End With
g.DrawImage(img, rect)
Dim DrawRect As Rectangle
'Sets the position of the mouse
finishX = e.X
finishY = e.Y
up = New Point(finishX, finishY)
'Sets the value of rectangle, x, y, width, height position
DrawRect = New Rectangle(Math.Min(up.X, down.X), Math.Min(up.Y, down.Y), Math.Abs(up.X - down.X), Math.Abs(up.Y - down.Y))
Dim myGraphics As Graphics
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(picImage .Handle)
myGraphics.DrawImage(img, rect, DrawRect, GraphicsUnit.Pixel)
'Dim b As SolidBrush = New SolidBrush(Color.White)
'g.FillRectangle(b, DrawRect)
''Creates an rectagnle on the picture box for visual.
'g = picImage.CreateGraphics
'g.FillRectangle(b, DrawRect)
g.Dispose()
objNewBmp.Dispose()
End Sub
'Opens selected image
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
openImage()
End Sub
'Opens an image to edit
Private Sub openImage()
If strFilePath = "" Then
cboFrameNo.Items.Clear()
OpenFileDialog1.ShowDialog ()
strFilePath = OpenFileDialog1.FileName.T oString
If strFilePath = "" Then
MsgBox("Please select an image")
OpenFileDialog1.ShowDialog ()
Else
MsgBox(strFilePath)
loadImage(strFilePath, strFilePath)
End If
Else
MsgBox("Please close the current image", MsgBoxStyle.Information)
End If
End Sub
Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
If strFilePath = "" Then
Exit Sub
Else
closeFile()
disposeFrame()
Exit Sub
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
saveImage()
End Sub
'Saves the edited image
Private Sub saveImage()
If checkPath() = True Then
SaveFileDialog1.AddExtensi on = True
SaveFileDialog1.ShowDialog ()
strFileName = SaveFileDialog1.FileName()
strFileName = strFileName & ".tif"
Me.Cursor = System.Windows.Forms.Curso rs.WaitCur sor
'Deletes the original edited pages. For example page 0.tif was edited
'and saved as 0s.tif. Now delete the 0.tif in order rename the
'0s.tif file to 0.tif. Then we can package all the page numbers back to
'one .tiff file
Dim saveTif As Bitmap = New Bitmap(strPath & curF & ".tif")
Dim myImageCodecInfo As ImageCodecInfo
Dim myEncoder As Encoder
Dim myEncoderParameter As EncoderParameter
Dim myEncoderParameters As EncoderParameters
'Get an ImageCodecInfo object that represents the TIFF codec.
myImageCodecInfo = GetEncoderInfo("image/tiff ")
'Create an Encoder object based on the GUID
'for the SaveFlag parameter category.
myEncoder = Encoder.SaveFlag
'Create an EncoderParameters object.
'An EncoderParameters object has an array of EncoderParameter
'objects. In this case, there is only one
'EncoderParameter object in the array.
myEncoderParameters = New EncoderParameters(1)
myEncoderParameter = New EncoderParameter(myEncoder , CLng(EncoderValue.MultiFra me))
myEncoderParameters.Param( 0) = myEncoderParameter
saveTif.Save(strFileName, myImageCodecInfo, myEncoderParameters)
Dim i As Integer
cboFrameNo.Items.RemoveAt( 0)
frameCount = cboFrameNo.Items.Count
'Removes the page 1 from the combo box. otherwise first page will be
'saved twice.
Try
For i = 0 To frameCount
pageNo = cboFrameNo.Items.Item(i)
If objfile.Exists(strPath & pageNo & ".tif") Then
Dim saveFrame As Bitmap = New Bitmap(strPath & pageNo & ".tif")
myEncoderParameter = New EncoderParameter(myEncoder , CLng(EncoderValue.FrameDim ensionPage ))
myEncoderParameters.Param( 0) = myEncoderParameter
saveTif.SaveAdd(saveFrame, myEncoderParameters)
saveFrame.Dispose()
End If
Next
Catch ex As Exception
End Try
saveTif.Dispose()
Me.Cursor = System.Windows.Forms.Curso rs.Default
MsgBox("File saved as" & strFileName)
ifSaved = True
If MsgBox("Do you want to close this image?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
closeFile()
Else
'Changes the file to newly saved file name and loads the saved file.
strFilePath = strFileName
isDelete = True
loadImage(strFileName, strFileName)
End If
Else
Exit Sub
End If
End Sub
'Deletes the saved individual frames
Private Sub disposeFrame()
Try
Dim i As Integer
frameCount = cboFrameNo.Items.Count
For i = 0 To frameCount
pageNo = cboFrameNo.Items.Item(i)
If objfile.Exists(strPath & pageNo & ".tif") Then
objfile.Delete(strPath & pageNo & ".tif")
End If
Next
Catch
End Try
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If checkPath() = True Then
'Check to see if the cursor is in Edit mode
If Me.Cursor Is System.Windows.Forms.Curso rs.Cross Then
MsgBox("You can not delete a page in Edit Mode. Please Change the mode to View Mode", MsgBoxStyle.Information)
Exit Sub
End If
If MsgBox("Do you want to delete page" & " " & curF, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
isDelete = True
cboFrameNo.Items.Remove(cu rF)
objfile.Delete(strPath & curF & ".tif")
nextFrame()
DisplayFrame()
isDelete = False
Else
Exit Sub
End If
Else
Exit Sub
End If
End Sub
'GetEncoderInfo
Private Shared Function GetEncoderInfo(ByVal mimeType As [String]) As ImageCodecInfo
Dim i As Integer
Dim encoders() As ImageCodecInfo
encoders = ImageCodecInfo.GetImageEnc oders()
For i = 0 To (encoders.Length - 1)
If (encoders(i).MimeType = mimeType) Then
Return encoders(i)
End If
Next i
End Function
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
closeFile()
End Sub
'Closes the open image file
Private Sub closeFile()
If checkPath() = True Then
If ifSaved = True Then
picImage.Image = Nothing
isDelete = True
strFilePath = ""
disposeFrame()
cboFrameNo.Items.Clear()
Else
If MsgBox("Do you want to close the image without saving?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
picImage.Image = Nothing
objImage.Dispose()
isDelete = True
strFilePath = ""
disposeFrame()
cboFrameNo.Items.Clear()
Else
Exit Sub
End If
End If
Else
Exit Sub
End If
End Sub
'Checks if there is an image loaded for editing.
Private Function checkPath() As Boolean
If strFilePath = "" Then
MsgBox("Select an image to edit", MsgBoxStyle.Information)
checkPath = False
Exit Function
Else
checkPath = True
End If
End Function
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
closeFile()
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
openImage()
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
saveImage()
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
If checkPath() = True Then
'using Acrobat.tlb
Dim acroapp As Object
Dim AcroExchApp As Object
AcroExchApp = CreateObject("AcroExch.App ")
acroapp = CreateObject("AcroExch.AVD oc")
acroapp.Open(strFilePath, "")
AcroExchApp.show()
End If
End Sub
Private Sub btnNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If checkPath() = True Then
Me.Cursor = System.Windows.Forms.Curso rs.Default
picBoxSize()
End If
End Sub
Private Sub btnActual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If checkPath() = True Then
actualSize()
End If
End Sub
Private Sub frmAeroTiffEditor_Closing( ByVal sender As Object, ByVal e As System.ComponentModel.Canc elEventArg s) Handles MyBase.Closing
disposeFrame()
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Cursor = System.Windows.Forms.Curso rs.Cross
End Sub
Private Sub picImage_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles picImage.MouseMove
lbl1.Text = e.X
lbl2.Text = e.Y
End Sub
Private Sub picImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picImage.Click
End Sub
End Class
Imports System.Drawing.Imaging
Imports System.IO.File
Public Class frmAeroTiffEditor
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents GroupBox As System.Windows.Forms.Group
Friend WithEvents btnClose As System.Windows.Forms.Butto
Friend WithEvents cboFrameNo As System.Windows.Forms.Combo
Friend WithEvents btnOpen As System.Windows.Forms.Butto
Friend WithEvents btnPrint As System.Windows.Forms.Butto
Friend WithEvents btnUnZoom As System.Windows.Forms.Butto
Friend WithEvents btnZoom As System.Windows.Forms.Butto
Friend WithEvents btnPrevious As System.Windows.Forms.Butto
Friend WithEvents btnNext As System.Windows.Forms.Butto
Friend WithEvents btnSave As System.Windows.Forms.Butto
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveF
Friend WithEvents MainMenu1 As System.Windows.Forms.MainM
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem10 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem12 As System.Windows.Forms.MenuI
Friend WithEvents ToolTip As System.Windows.Forms.ToolT
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenF
Friend WithEvents picImage As System.Windows.Forms.Pictu
Friend WithEvents lbl1 As System.Windows.Forms.Label
Friend WithEvents lbl2 As System.Windows.Forms.Label
<System.Diagnostics.Debugg
Me.components = New System.ComponentModel.Cont
Dim resources As System.Resources.ResourceM
Me.GroupBox = New System.Windows.Forms.Group
Me.lbl2 = New System.Windows.Forms.Label
Me.lbl1 = New System.Windows.Forms.Label
Me.btnClose = New System.Windows.Forms.Butto
Me.cboFrameNo = New System.Windows.Forms.Combo
Me.btnOpen = New System.Windows.Forms.Butto
Me.btnPrint = New System.Windows.Forms.Butto
Me.btnUnZoom = New System.Windows.Forms.Butto
Me.btnZoom = New System.Windows.Forms.Butto
Me.btnPrevious = New System.Windows.Forms.Butto
Me.btnNext = New System.Windows.Forms.Butto
Me.btnSave = New System.Windows.Forms.Butto
Me.SaveFileDialog1 = New System.Windows.Forms.SaveF
Me.MainMenu1 = New System.Windows.Forms.MainM
Me.MenuItem1 = New System.Windows.Forms.MenuI
Me.MenuItem2 = New System.Windows.Forms.MenuI
Me.MenuItem3 = New System.Windows.Forms.MenuI
Me.MenuItem4 = New System.Windows.Forms.MenuI
Me.MenuItem6 = New System.Windows.Forms.MenuI
Me.MenuItem7 = New System.Windows.Forms.MenuI
Me.MenuItem9 = New System.Windows.Forms.MenuI
Me.MenuItem8 = New System.Windows.Forms.MenuI
Me.MenuItem10 = New System.Windows.Forms.MenuI
Me.MenuItem12 = New System.Windows.Forms.MenuI
Me.ToolTip = New System.Windows.Forms.ToolT
Me.OpenFileDialog1 = New System.Windows.Forms.OpenF
Me.picImage = New System.Windows.Forms.Pictu
Me.GroupBox.SuspendLayout(
Me.SuspendLayout()
'
'GroupBox
'
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Controls.Add(M
Me.GroupBox.Location = New System.Drawing.Point(3, -1)
Me.GroupBox.Name = "GroupBox"
Me.GroupBox.Size = New System.Drawing.Size(608, 32)
Me.GroupBox.TabIndex = 25
Me.GroupBox.TabStop = False
'
'lbl2
'
Me.lbl2.Location = New System.Drawing.Point(472, 8)
Me.lbl2.Name = "lbl2"
Me.lbl2.Size = New System.Drawing.Size(72, 16)
Me.lbl2.TabIndex = 37
'
'lbl1
'
Me.lbl1.Location = New System.Drawing.Point(392, 8)
Me.lbl1.Name = "lbl1"
Me.lbl1.Size = New System.Drawing.Size(72, 16)
Me.lbl1.TabIndex = 36
'
'btnClose
'
Me.btnClose.Image = CType(resources.GetObject(
Me.btnClose.Location = New System.Drawing.Point(64, 8)
Me.btnClose.Name = "btnClose"
Me.btnClose.Size = New System.Drawing.Size(32, 24)
Me.btnClose.TabIndex = 35
Me.ToolTip.SetToolTip(Me.b
'
'cboFrameNo
'
Me.cboFrameNo.Location = New System.Drawing.Point(192, 8)
Me.cboFrameNo.Name = "cboFrameNo"
Me.cboFrameNo.Size = New System.Drawing.Size(48, 19)
Me.cboFrameNo.TabIndex = 34
'
'btnOpen
'
Me.btnOpen.Image = CType(resources.GetObject(
Me.btnOpen.Location = New System.Drawing.Point(0, 8)
Me.btnOpen.Name = "btnOpen"
Me.btnOpen.Size = New System.Drawing.Size(32, 24)
Me.btnOpen.TabIndex = 27
'
'btnPrint
'
Me.btnPrint.Image = CType(resources.GetObject(
Me.btnPrint.Location = New System.Drawing.Point(96, 8)
Me.btnPrint.Name = "btnPrint"
Me.btnPrint.Size = New System.Drawing.Size(32, 24)
Me.btnPrint.TabIndex = 26
'
'btnUnZoom
'
Me.btnUnZoom.Image = CType(resources.GetObject(
Me.btnUnZoom.Location = New System.Drawing.Point(304, 8)
Me.btnUnZoom.Name = "btnUnZoom"
Me.btnUnZoom.Size = New System.Drawing.Size(32, 24)
Me.btnUnZoom.TabIndex = 24
'
'btnZoom
'
Me.btnZoom.Image = CType(resources.GetObject(
Me.btnZoom.Location = New System.Drawing.Point(336, 8)
Me.btnZoom.Name = "btnZoom"
Me.btnZoom.Size = New System.Drawing.Size(32, 24)
Me.btnZoom.TabIndex = 23
'
'btnPrevious
'
Me.btnPrevious.Image = CType(resources.GetObject(
Me.btnPrevious.Location = New System.Drawing.Point(160, 8)
Me.btnPrevious.Name = "btnPrevious"
Me.btnPrevious.Size = New System.Drawing.Size(32, 24)
Me.btnPrevious.TabIndex = 22
'
'btnNext
'
Me.btnNext.Image = CType(resources.GetObject(
Me.btnNext.Location = New System.Drawing.Point(240, 8)
Me.btnNext.Name = "btnNext"
Me.btnNext.Size = New System.Drawing.Size(32, 24)
Me.btnNext.TabIndex = 21
'
'btnSave
'
Me.btnSave.Image = CType(resources.GetObject(
Me.btnSave.Location = New System.Drawing.Point(32, 8)
Me.btnSave.Name = "btnSave"
Me.btnSave.Size = New System.Drawing.Size(32, 24)
Me.btnSave.TabIndex = 20
Me.ToolTip.SetToolTip(Me.b
'
'SaveFileDialog1
'
Me.SaveFileDialog1.FileNam
'
'MainMenu1
'
Me.MainMenu1.MenuItems.Add
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.Add
Me.MenuItem1.Text = "File"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Shortcut = System.Windows.Forms.Short
Me.MenuItem2.Text = "Open"
'
'MenuItem3
'
Me.MenuItem3.Index = 1
Me.MenuItem3.Shortcut = System.Windows.Forms.Short
Me.MenuItem3.Text = "Save"
'
'MenuItem4
'
Me.MenuItem4.Index = 2
Me.MenuItem4.Shortcut = System.Windows.Forms.Short
Me.MenuItem4.Text = "Close"
'
'MenuItem6
'
Me.MenuItem6.Index = 3
Me.MenuItem6.Shortcut = System.Windows.Forms.Short
Me.MenuItem6.Text = "Exit"
'
'MenuItem7
'
Me.MenuItem7.Index = 1
Me.MenuItem7.MenuItems.Add
Me.MenuItem7.Text = "Toolbar"
'
'MenuItem9
'
Me.MenuItem9.Index = 0
Me.MenuItem9.Text = "Show"
'
'MenuItem8
'
Me.MenuItem8.Index = 1
Me.MenuItem8.Text = "Hide"
'
'MenuItem10
'
Me.MenuItem10.Index = 2
Me.MenuItem10.MenuItems.Ad
Me.MenuItem10.Text = "Help"
'
'MenuItem12
'
Me.MenuItem12.Index = 0
Me.MenuItem12.Text = "About"
'
'ToolTip
'
Me.ToolTip.ShowAlways = True
'
'picImage
'
Me.picImage.Anchor = CType((((System.Windows.Fo
Or System.Windows.Forms.Ancho
Or System.Windows.Forms.Ancho
Me.picImage.BackColor = System.Drawing.Color.Gains
Me.picImage.Cursor = System.Windows.Forms.Curso
Me.picImage.Location = New System.Drawing.Point(8, 40)
Me.picImage.Name = "picImage"
Me.picImage.Size = New System.Drawing.Size(603, 639)
Me.picImage.TabIndex = 24
Me.picImage.TabStop = False
'
'frmAeroTiffEditor
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 13)
Me.AutoScroll = True
Me.ClientSize = New System.Drawing.Size(614, 679)
Me.Controls.Add(Me.GroupBo
Me.Controls.Add(Me.picImag
Me.Font = New System.Drawing.Font("Batan
Me.Icon = CType(resources.GetObject(
Me.Name = "frmAeroTiffEditor"
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormS
Me.Text = "AeroControlex Tiff Viewer"
Me.GroupBox.ResumeLayout(F
Me.ResumeLayout(False)
End Sub
#End Region
Dim curF As Integer
Dim finishX, finishY As Integer
Dim startX, startY As Integer
Dim up, down As Point
Dim strFilePath As String
Dim strPath As String
Dim strFileName As String
Dim g As Graphics
Dim totFrame As Integer
Dim frameCount As String
Dim pageNo As Integer
Dim objfile As System.IO.File
Dim objImage As System.Drawing.Image
Dim ifSaved As Boolean = False
Dim isDelete As Boolean = False
Dim isEdit As Boolean = False
Private _instance As String = 1
Public Property InstanceName() As String
Get
Return _instance
End Get
Set(ByVal Value As String)
_instance = Value
End Set
End Property
'Loads the .Tiff file and saves every frame as a seperate .tiff file
Public Sub loadImage(ByVal strFilePath As String, ByVal ImageCaption As String)
picBoxSize()
ifSaved = False
cboFrameNo.Items.Clear()
'Changed the cursor to waitCursor
Me.Cursor = System.Windows.Forms.Curso
'Sets the tiff file as an image object.
objImage = objImage.FromFile(strFileP
Dim objGuid As Guid = (objImage.FrameDimensionsL
Dim objDimension As System.Drawing.Imaging.Fra
'Gets the total number of frames in the .tiff file
totFrame = objImage.GetFrameCount(obj
'Adds number of frames to the combo box for displaying purposes.
Dim i As Integer
For i = 0 To totFrame - 1
cboFrameNo.Items.Add(i)
Next
cboFrameNo.Items.IndexOf(1
'Sets the temporary folder to "C:\temp\"
strPath = "c:\temp\" & _instance
'Saves every frame as a seperate file.
Dim z As Integer
z = 0
curF = 0
For z = 0 To (totFrame - 1)
objImage.SelectActiveFrame
objImage.Save(strPath & curF & ".tif", Imaging.ImageFormat.Tiff)
curF = curF + 1
Next
curF = 0
'set window caption
Me.Text = ImageCaption
'Displayes the frames
DisplayFrame()
Me.Cursor = System.Windows.Forms.Curso
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Sets the tooltip text's
ToolTip.SetToolTip(btnOpen
ToolTip.SetToolTip(btnSave
ToolTip.SetToolTip(btnPrin
ToolTip.SetToolTip(btnPrev
ToolTip.SetToolTip(btnNext
ToolTip.SetToolTip(cboFram
ToolTip.SetToolTip(btnUnZo
ToolTip.SetToolTip(btnZoom
curF = 0
End Sub
'on click displays the next page
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If checkPath() = True Then
btnPrevious.Enabled = True
If isEdit = True Then
isDelete = False
Else
isDelete = True
End If
nextFrame()
DisplayFrame()
Else
Exit Sub
End If
End Sub
'Gets the next frame number
Private Sub nextFrame()
If curF = totFrame - 1 Then
btnNext.Enabled = False
Exit Sub
Else
curF = curF + 1
End If
End Sub
'on click displays the previous frame
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
If checkPath() = True Then
btnNext.Enabled = True
If isEdit = True Then
isDelete = False
Else
isDelete = True
End If
previousFrame()
DisplayFrame()
Else
Exit Sub
End If
End Sub
'gets the previous frame number
Public Sub previousFrame()
If curF = 0 Then
btnPrevious.Enabled = False
Exit Sub
Else
curF = curF - 1
End If
End Sub
'Displays the selected frame
Private Sub DisplayFrame()
'if isDelete is true sets the image as the original .tiff image
'if inDelete is false sets the imahe as seperate file from the temp folder
Select Case isDelete
Case True
Dim objImage As System.Drawing.Image = objImage.FromFile(strFileP
Case False
Dim objImage As System.Drawing.Image = objImage.FromFile(strPath & curF & ".tif")
strFilePath = strPath & curF & ".tif"
End Select
Dim objGuid As Guid = (objImage.FrameDimensionsL
Dim objDimension As System.Drawing.Imaging.Fra
objImage.SelectActiveFrame
picImage.Image = objImage
picImage.SizeMode = PictureBoxSizeMode.Stretch
cboFrameNo.Text = curF
End Sub
'Gets the selected frame number for display from combo box
Private Sub cboFrameNo_SelectedIndexCh
curF = cboFrameNo.Text
If curF = totFrame - 1 Then
btnNext.Enabled = True
Exit Sub
Else
DisplayFrame()
End If
End Sub
'on click zooms the image by 1.25 %
Private Sub btnZoom_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoom.Click
If checkPath() = True Then
picImage.Width = CInt(picImage.Width * 1.25)
picImage.Height = CInt(picImage.Height * 1.25)
Else
Exit Sub
End If
End Sub
'on click unzooms the image by 1.25%
Private Sub btnUnZoom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnZoom.Click
If checkPath() = True Then
picImage.Width = CInt(picImage.Width / 1.25)
picImage.Height = CInt(picImage.Height / 1.25)
Else
Exit Sub
End If
End Sub
'Gets the ctual size of the image
Private Sub actualSize()
picImage.Width = objImage.Width
picImage.Height = objImage.Height
End Sub
Private Sub picBoxSize()
picImage.Width = 600
picImage.Height = 640
End Sub
'Gets the cross cursor
Private Sub btnErase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If checkPath() = True Then
MsgBox("Screen will change to Edit Mode", MsgBoxStyle.Critical)
Me.Cursor = System.Windows.Forms.Curso
isEdit = True
isDelete = False
actualSize()
DisplayFrame()
Else
Exit Sub
End If
End Sub
'on mouse down gets the x,y position of the mouse
Public Sub mDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse
'Checks if left mouse button in clicked
If e.Button <> MouseButtons.Left Then
Exit Sub
Else
'Gets starting position of the mouse
startX = e.X
startY = e.Y
down = New Point(startX, startY)
End If
End Sub
'on mouse up gets the x,y position of the mouse and draws user defined
'rectangle. Then saves the page as curF & "s" & ".tif"
Private Sub mUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse
'objNewBmp.Dispose()
Dim img As Drawing.Image
'sets the current page as image.
img = picImage.Image
Dim objBmp As New Bitmap(img, img.Width, img.Height)
Dim objNewBmp As New Bitmap(objBmp.Width, objBmp.Height, Imaging.PixelFormat.Format
Dim g As Graphics
g = Graphics.FromImage(objNewB
'Creats a duplicate image file as bitmap format
Dim rect As Rectangle
With rect
.Width = img.Width
.Height = img.Height
.X = 0
.Y = 0
End With
g.DrawImage(img, rect)
Dim DrawRect As Rectangle
'Sets the position of the mouse
finishX = e.X
finishY = e.Y
up = New Point(finishX, finishY)
'Sets the value of rectangle, x, y, width, height position
DrawRect = New Rectangle(Math.Min(up.X, down.X), Math.Min(up.Y, down.Y), Math.Abs(up.X - down.X), Math.Abs(up.Y - down.Y))
Dim myGraphics As Graphics
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(picImage
myGraphics.DrawImage(img, rect, DrawRect, GraphicsUnit.Pixel)
'Dim b As SolidBrush = New SolidBrush(Color.White)
'g.FillRectangle(b, DrawRect)
''Creates an rectagnle on the picture box for visual.
'g = picImage.CreateGraphics
'g.FillRectangle(b, DrawRect)
g.Dispose()
objNewBmp.Dispose()
End Sub
'Opens selected image
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
openImage()
End Sub
'Opens an image to edit
Private Sub openImage()
If strFilePath = "" Then
cboFrameNo.Items.Clear()
OpenFileDialog1.ShowDialog
strFilePath = OpenFileDialog1.FileName.T
If strFilePath = "" Then
MsgBox("Please select an image")
OpenFileDialog1.ShowDialog
Else
MsgBox(strFilePath)
loadImage(strFilePath, strFilePath)
End If
Else
MsgBox("Please close the current image", MsgBoxStyle.Information)
End If
End Sub
Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
If strFilePath = "" Then
Exit Sub
Else
closeFile()
disposeFrame()
Exit Sub
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
saveImage()
End Sub
'Saves the edited image
Private Sub saveImage()
If checkPath() = True Then
SaveFileDialog1.AddExtensi
SaveFileDialog1.ShowDialog
strFileName = SaveFileDialog1.FileName()
strFileName = strFileName & ".tif"
Me.Cursor = System.Windows.Forms.Curso
'Deletes the original edited pages. For example page 0.tif was edited
'and saved as 0s.tif. Now delete the 0.tif in order rename the
'0s.tif file to 0.tif. Then we can package all the page numbers back to
'one .tiff file
Dim saveTif As Bitmap = New Bitmap(strPath & curF & ".tif")
Dim myImageCodecInfo As ImageCodecInfo
Dim myEncoder As Encoder
Dim myEncoderParameter As EncoderParameter
Dim myEncoderParameters As EncoderParameters
'Get an ImageCodecInfo object that represents the TIFF codec.
myImageCodecInfo = GetEncoderInfo("image/tiff
'Create an Encoder object based on the GUID
'for the SaveFlag parameter category.
myEncoder = Encoder.SaveFlag
'Create an EncoderParameters object.
'An EncoderParameters object has an array of EncoderParameter
'objects. In this case, there is only one
'EncoderParameter object in the array.
myEncoderParameters = New EncoderParameters(1)
myEncoderParameter = New EncoderParameter(myEncoder
myEncoderParameters.Param(
saveTif.Save(strFileName, myImageCodecInfo, myEncoderParameters)
Dim i As Integer
cboFrameNo.Items.RemoveAt(
frameCount = cboFrameNo.Items.Count
'Removes the page 1 from the combo box. otherwise first page will be
'saved twice.
Try
For i = 0 To frameCount
pageNo = cboFrameNo.Items.Item(i)
If objfile.Exists(strPath & pageNo & ".tif") Then
Dim saveFrame As Bitmap = New Bitmap(strPath & pageNo & ".tif")
myEncoderParameter = New EncoderParameter(myEncoder
myEncoderParameters.Param(
saveTif.SaveAdd(saveFrame,
saveFrame.Dispose()
End If
Next
Catch ex As Exception
End Try
saveTif.Dispose()
Me.Cursor = System.Windows.Forms.Curso
MsgBox("File saved as" & strFileName)
ifSaved = True
If MsgBox("Do you want to close this image?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
closeFile()
Else
'Changes the file to newly saved file name and loads the saved file.
strFilePath = strFileName
isDelete = True
loadImage(strFileName, strFileName)
End If
Else
Exit Sub
End If
End Sub
'Deletes the saved individual frames
Private Sub disposeFrame()
Try
Dim i As Integer
frameCount = cboFrameNo.Items.Count
For i = 0 To frameCount
pageNo = cboFrameNo.Items.Item(i)
If objfile.Exists(strPath & pageNo & ".tif") Then
objfile.Delete(strPath & pageNo & ".tif")
End If
Next
Catch
End Try
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If checkPath() = True Then
'Check to see if the cursor is in Edit mode
If Me.Cursor Is System.Windows.Forms.Curso
MsgBox("You can not delete a page in Edit Mode. Please Change the mode to View Mode", MsgBoxStyle.Information)
Exit Sub
End If
If MsgBox("Do you want to delete page" & " " & curF, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
isDelete = True
cboFrameNo.Items.Remove(cu
objfile.Delete(strPath & curF & ".tif")
nextFrame()
DisplayFrame()
isDelete = False
Else
Exit Sub
End If
Else
Exit Sub
End If
End Sub
'GetEncoderInfo
Private Shared Function GetEncoderInfo(ByVal mimeType As [String]) As ImageCodecInfo
Dim i As Integer
Dim encoders() As ImageCodecInfo
encoders = ImageCodecInfo.GetImageEnc
For i = 0 To (encoders.Length - 1)
If (encoders(i).MimeType = mimeType) Then
Return encoders(i)
End If
Next i
End Function
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
closeFile()
End Sub
'Closes the open image file
Private Sub closeFile()
If checkPath() = True Then
If ifSaved = True Then
picImage.Image = Nothing
isDelete = True
strFilePath = ""
disposeFrame()
cboFrameNo.Items.Clear()
Else
If MsgBox("Do you want to close the image without saving?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
picImage.Image = Nothing
objImage.Dispose()
isDelete = True
strFilePath = ""
disposeFrame()
cboFrameNo.Items.Clear()
Else
Exit Sub
End If
End If
Else
Exit Sub
End If
End Sub
'Checks if there is an image loaded for editing.
Private Function checkPath() As Boolean
If strFilePath = "" Then
MsgBox("Select an image to edit", MsgBoxStyle.Information)
checkPath = False
Exit Function
Else
checkPath = True
End If
End Function
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
closeFile()
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
openImage()
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
saveImage()
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
If checkPath() = True Then
'using Acrobat.tlb
Dim acroapp As Object
Dim AcroExchApp As Object
AcroExchApp = CreateObject("AcroExch.App
acroapp = CreateObject("AcroExch.AVD
acroapp.Open(strFilePath, "")
AcroExchApp.show()
End If
End Sub
Private Sub btnNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If checkPath() = True Then
Me.Cursor = System.Windows.Forms.Curso
picBoxSize()
End If
End Sub
Private Sub btnActual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If checkPath() = True Then
actualSize()
End If
End Sub
Private Sub frmAeroTiffEditor_Closing(
disposeFrame()
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Cursor = System.Windows.Forms.Curso
End Sub
Private Sub picImage_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
lbl1.Text = e.X
lbl2.Text = e.Y
End Sub
Private Sub picImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picImage.Click
End Sub
End Class
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks, that will help out
ASKER
Chaosian, It's not exactly what I was looking for and I'm still having problems with the code, but your code does work and I can use it as a new starting point.
ASKER
even though it was my code to begin with, ;)