Click here to Skip to main content
15,902,299 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralListView: Display only txt files Pin
Brad Fackrell27-Jul-04 7:16
Brad Fackrell27-Jul-04 7:16 
GeneralRe: ListView: Display only txt files Pin
Dave Kreskowiak27-Jul-04 10:11
mveDave Kreskowiak27-Jul-04 10:11 
GeneralRe: ListView: Display only txt files Pin
Brad Fackrell27-Jul-04 10:50
Brad Fackrell27-Jul-04 10:50 
GeneralOracleClient Pin
beowulfagate26-Jul-04 17:54
beowulfagate26-Jul-04 17:54 
QuestionHow can I put the MMC snap-in in a Web browser? Pin
zzzhouzhou26-Jul-04 16:38
zzzhouzhou26-Jul-04 16:38 
GeneralMultiple Bitmaps Pin
maykut209926-Jul-04 14:55
maykut209926-Jul-04 14:55 
GeneralRe: Multiple Bitmaps Pin
Dave Kreskowiak27-Jul-04 7:01
mveDave Kreskowiak27-Jul-04 7:01 
GeneralRe: Multiple Bitmaps Pin
maykut209928-Jul-04 13:51
maykut209928-Jul-04 13:51 
what i mean is that when I click on a button called Add Frames, it adds each animation frame onto seperate picture boxes, which displays each animation frame as a bitmap on seperate picture box. This is what I want to save. I will list my code here. If you go through my code you will see that each each animation frame of a gif is separteley displayed on seprate picture boxes this is what i want to save, all individual bitmaps which are on their own picture boxes as a complete bitmap or jpeg. here is my code:

This is my animation class that grabs each frame of the animation:

Imports System
Imports System.Drawing
Imports System.Drawing.Image
Imports System.Runtime.Serialization.Formatters.Binary
Public Class Animation
Implements IDisposable
Dim m_Img As System.Drawing.Image
Dim m_Frames As New System.Collections.ArrayList
Dim m_FrameCount As Integer
Dim i As Integer = 0
Dim m_Width, m_Height, xWidth, yHeight As Integer
Dim array As New ArrayList
Dim FCount As Integer

Public Sub New(ByVal imgPath As String)
'Load Image
m_Img = System.Drawing.Image.FromFile(imgPath)
xWidth = m_Img.Width
yHeight = m_Img.Height
'Check if It's an Animation
If System.Drawing.ImageAnimator.CanAnimate(m_Img) = False Then
m_Img.Dispose()

'if not animation throe a new exception
Throw New Exception("This is not a Animation")
End If

'Count Animation Frames
Dim fdl As New Drawing.Imaging.FrameDimension(m_Img.FrameDimensionsList(0))
m_FrameCount = m_Img.GetFrameCount(fdl)

'extract the first frame and start animation to extract all frames
AddCurrentFrame()
System.Drawing.ImageAnimator.Animate(m_Img, New EventHandler(AddressOf OnFrameChanged))

Do 'Loop until end of frame
Loop Until Done

End Sub

Public Sub Dispose() Implements System.IDisposable.Dispose
StopAnimate()
End Sub

Public ReadOnly Property FrameCount() As Integer
Get
Return m_FrameCount
End Get
End Property
Public ReadOnly Property AnimWidth() As Integer
Get
Return xWidth
End Get
End Property
Public ReadOnly Property AnimHeight() As Integer
Get
Return yHeight
End Get
End Property
Public ReadOnly Property Frame(ByVal index As Integer) As System.Drawing.Bitmap
Get
Return DirectCast(m_Frames(index), System.Drawing.Bitmap)
End Get
End Property

Private Sub OnFrameChanged(ByVal sender As Object, ByVal e As EventArgs)
If Done Then
StopAnimate()
Exit Sub
End If

System.Drawing.ImageAnimator.UpdateFrames(m_Img)
AddCurrentFrame()
End Sub

Private Sub AddCurrentFrame()

'Create new Empty Bitmap
Dim bmp As New Bitmap(xWidth, yHeight)
Dim pos, pos2 As Point
Dim g As Graphics = System.Drawing.Graphics.FromImage(DirectCast(bmp, System.Drawing.Image))

pos = New Point(0, 0)
g.DrawImage(m_Img, pos)
m_Frames.Add(bmp)

'g.DrawImage(m_Img, New Rectangle(i, 0, xWidth, yHeight))
'm_Frames.Add(bmp)

End Sub
' Return True when the class has extracted all the frames
Private ReadOnly Property Done() As Boolean
Get
Return m_Frames.Count = FrameCount
End Get
End Property

' Stop the animation and dispose the open image object
Private Sub StopAnimate()
System.Drawing.ImageAnimator.StopAnimate(m_Img, _
New EventHandler(AddressOf OnFrameChanged))
m_Img.Dispose()
End Sub
Public Sub NextFrame()
i = i + xWidth
End Sub
End Class

and Here is my main code:

Imports System
Imports System.Drawing
Imports System.Drawing.Image
Imports System.Drawing.Imaging
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Dim i As Integer = 1
Dim count As Integer = 1
Dim bmp As Bitmap
Dim g As Graphics = CreateGraphics()
Dim im() As Image
Dim strFileName As String
Dim rect As Rectangle
Dim m_MouseDown As Boolean = False
Dim Anim As Animation
Dim PicBoxCount As Integer = 1
Dim FrameCount As Integer = 1
Dim xPos As Integer = 0
Dim yPos As Integer = 32
Dim PictureBox() As PictureBox
'Dim sz As Size
'Dim sz As New Size(100, 60)

#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.IContainer

'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 MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
Friend WithEvents tb As System.Windows.Forms.ToolBar
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
Friend WithEvents btnNew As System.Windows.Forms.ToolBarButton
Friend WithEvents btnOpen As System.Windows.Forms.ToolBarButton
Friend WithEvents btnSave As System.Windows.Forms.ToolBarButton
Friend WithEvents btnDraw As System.Windows.Forms.ToolBarButton
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
Friend WithEvents HScrollBar1 As System.Windows.Forms.HScrollBar
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem5 = New System.Windows.Forms.MenuItem
Me.MenuItem8 = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.MenuItem7 = New System.Windows.Forms.MenuItem
Me.tb = New System.Windows.Forms.ToolBar
Me.btnNew = New System.Windows.Forms.ToolBarButton
Me.btnOpen = New System.Windows.Forms.ToolBarButton
Me.btnSave = New System.Windows.Forms.ToolBarButton
Me.btnDraw = New System.Windows.Forms.ToolBarButton
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.HScrollBar1 = New System.Windows.Forms.HScrollBar
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.MenuItem9 = New System.Windows.Forms.MenuItem
Me.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem6, Me.MenuItem9})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem5, Me.MenuItem8})
Me.MenuItem1.Text = "File"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "Open"
'
'MenuItem3
'
Me.MenuItem3.Index = 1
Me.MenuItem3.Text = "Save"
'
'MenuItem4
'
Me.MenuItem4.Index = 2
Me.MenuItem4.Text = "Save As.."
'
'MenuItem5
'
Me.MenuItem5.Index = 3
Me.MenuItem5.Text = "Exit"
'
'MenuItem8
'
Me.MenuItem8.Index = 4
Me.MenuItem8.Text = "Load Animation"
'
'MenuItem6
'
Me.MenuItem6.Index = 1
Me.MenuItem6.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem7})
Me.MenuItem6.Text = "Insert"
'
'MenuItem7
'
Me.MenuItem7.Index = 0
Me.MenuItem7.Text = "Insert Image"
'
'tb
'
Me.tb.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.btnNew, Me.btnOpen, Me.btnSave, Me.btnDraw})
Me.tb.DropDownArrows = True
Me.tb.ImageList = Me.ImageList1
Me.tb.Location = New System.Drawing.Point(0, 0)
Me.tb.Name = "tb"
Me.tb.ShowToolTips = True
Me.tb.Size = New System.Drawing.Size(736, 28)
Me.tb.TabIndex = 2
'
'btnNew
'
Me.btnNew.ImageIndex = 0
Me.btnNew.ToolTipText = "New"
'
'btnOpen
'
Me.btnOpen.ImageIndex = 1
Me.btnOpen.ToolTipText = "Open Graphics"
'
'btnSave
'
Me.btnSave.ImageIndex = 2
Me.btnSave.ToolTipText = "Save Graphics"
'
'btnDraw
'
Me.btnDraw.ImageIndex = 3
Me.btnDraw.ToolTipText = "Draw Graphics in Memory"
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'HScrollBar1
'
Me.HScrollBar1.Location = New System.Drawing.Point(0, 328)
Me.HScrollBar1.Name = "HScrollBar1"
Me.HScrollBar1.Size = New System.Drawing.Size(728, 16)
Me.HScrollBar1.TabIndex = 3
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(0, 32)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(736, 288)
Me.PictureBox1.TabIndex = 4
Me.PictureBox1.TabStop = False
'
'MenuItem9
'
Me.MenuItem9.Index = 2
Me.MenuItem9.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(736, 345)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.HScrollBar1)
Me.Controls.Add(Me.tb)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Dim oFileOpen As New OpenFileDialog
oFileOpen.Filter = "All Files|*.*|Bitmap|*.bmp|Gif|*.gif|Jpeg|*.jpg|PNG File|*.png"
'oFileOpen.Filter = "All Files(*.*)|*.*|Bitmap(*.bmp)|*.bmp|Gif(*.gif)|*.gif|Jpeg(*.jpg)|*.jpg||PNG Files(*.png)|*.png"
oFileOpen.ShowDialog()
strFileName = oFileOpen.FileName
If strFileName = Nothing Then Exit Sub
'Dim bmp As New Bitmap(strFileName)
ReDim Preserve im(i)
im(i) = New Bitmap(strFileName)

'bmp = New Bitmap(strFileName)
'ReDim Preserve bmp(i)
i = i + 1
'vPicBox.Image = bmp
'PictureBox1.Image = bmp

'bmp(i).FromFile(strFileName)
'i = i + 1
'PictureBox1.Image = bmp(i)
'bmp(i) = New Bitmap


'Dim bmp As New Bitmap(strFileName)
'PictureBox1.Image = bmp
End Sub

Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click
Dim oFileOpen As New OpenFileDialog
oFileOpen.Filter = "All Files|*.*|Bitmap|*.bmp|Gif|*.gif|Jpeg|*.jpg|PNG File|*.png"
'oFileOpen.Filter = "All Files(*.*)|*.*|Bitmap(*.bmp)|*.bmp|Gif(*.gif)|*.gif|Jpeg(*.jpg)|*.jpg||PNG Files(*.png)|*.png"
oFileOpen.ShowDialog()
strFileName = oFileOpen.FileName
If strFileName = Nothing Then Exit Sub
ReDim Preserve im(i)
im(i) = New Bitmap(strFileName)
i = i + 1
'Dim bmps As New Bitmap(strFileName)
'Dim im As Image
'Dim Rec As Rectangle
'bmp.p
'Rec = New Rectangle(10, 10, bmp.Width, bmp.Height)
'im.
'PictureBox1.Image = bmps

End Sub
Protected Overrides Sub OnDragEnter(ByVal e As DragEventArgs)

If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim allow As Boolean = True
Dim s As String
For Each s In CType(e.Data.GetData(DataFormats.FileDrop), String())
Dim ext As String = Path.GetExtension(s).ToLower()
If Not (ext = ".jpg" OrElse ext = ".jpeg" OrElse ext = ".tif" OrElse ext = ".gif" OrElse ext = ".bmp") Then
allow = False
End If
Next s
If allow Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End If
End Sub 'OnDragEnter


Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
Application.Exit()
End Sub

Private Sub tb_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tb.ButtonClick
Dim index As Integer

index = e.Button.ImageIndex

Select Case index
Case 0
i = 1
count = 1
Case 1
Case 2
Case 3
Try
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Working Code using multiple picture boxes
Dim xSize, ySize As Integer
xSize = Anim.AnimWidth
ySize = Anim.AnimHeight
Dim sz As New Size(xSize, ySize)
Dim AnimFrame As Bitmap = Anim.Frame(FrameCount)
Dim pos As Point

ReDim Preserve PictureBox(FrameCount)
pos = New Point(xPos, yPos)
PictureBox(FrameCount) = New PictureBox
PictureBox(FrameCount).Size = sz
PictureBox(FrameCount).Location = pos
PictureBox(FrameCount).BackColor = Color.Blue
Me.Controls.Add(PictureBox(FrameCount))
PictureBox1.Controls.Add(PictureBox(FrameCount))
PictureBox(FrameCount).Image = AnimFrame

FrameCount = FrameCount + 1
xPos = xPos + xSize
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


'Dim AnimFrame As Bitmap = Anim.Frame(FrameCount)
'PictureBox1.Image = AnimFrame
'FrameCount = FrameCount + 1
'Anim.NextFrame()
'Dim AnimFrame2 As Bitmap = Anim.Frame(FrameCount)
'PictureBox1.Image = AnimFrame
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Select

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'vPicBox.AllowDrop = True
End Sub

'Private Sub oPicBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
'If Not vPicBox.Image Is Nothing Then
'm_MouseDown = True
'End If
'End Sub
'Private Sub oPicBox_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
'If m_MouseDown Then
'vPicBox.DoDragDrop(oPicBox.Image, DragDropEffects.Copy Or DragDropEffects.Move)
'Else
'm_MouseDown = False
'End If
'End Sub

'Private Sub vPicBox_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs)
'If e.Data.GetDataPresent(DataFormats.Bitmap) Then
'If e.KeyState = 9 Then
'e.Effect = DragDropEffects.Copy
'Else
'e.Effect = DragDropEffects.Move
'End If
'Else
'e.Effect = DragDropEffects.None
'End If
'End Sub

'Private Sub vPicBox_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs)
'vPicBox.Image = e.Data.GetData(DataFormats.Bitmap)
'If Not e.KeyState = 8 Then
'oPicBox.Image = Nothing
'End If
'End Sub

Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
Dim oFileOpen As New OpenFileDialog
Dim i As Integer = 1
oFileOpen.Filter = "Animation|*.gif"
'oFileOpen.Filter = "All Files(*.*)|*.*|Bitmap(*.bmp)|*.bmp|Gif(*.gif)|*.gif|Jpeg(*.jpg)|*.jpg||PNG Files(*.png)|*.png"
oFileOpen.ShowDialog()
strFileName = oFileOpen.FileName
If strFileName = Nothing Then Exit Sub
Anim = New Animation(strFileName)
End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
Dim oSaveFile As New SaveFileDialog
oSaveFile.Filter = "Bitmap|*.bmp"
oSaveFile.ShowDialog()
Dim strSaveName As String = oSaveFile.FileName.ToLower
'Dim myBitmap As Bitmap = PictureBox().image
Dim bmp As Bitmap
Dim im As Image


'Dim myBitmap As Bitmap = PictureBox1.Image
'myBitmap.Save(strSaveName, ImageFormat.Bmp)

End Sub
End Class
GeneralRe: Multiple Bitmaps Pin
Dave Kreskowiak28-Jul-04 14:16
mveDave Kreskowiak28-Jul-04 14:16 
GeneralRe: Multiple Bitmaps Pin
maykut209928-Jul-04 14:21
maykut209928-Jul-04 14:21 
GeneralRe: Multiple Bitmaps Pin
Aaron Eldreth29-Jul-04 17:10
Aaron Eldreth29-Jul-04 17:10 
GeneralRe: Multiple Bitmaps Pin
maykut209929-Jul-04 17:21
maykut209929-Jul-04 17:21 
Generalquestions in vb.net Pin
ahmad_yossef26-Jul-04 0:35
ahmad_yossef26-Jul-04 0:35 
GeneralRe: questions in vb.net Pin
Dave Kreskowiak27-Jul-04 3:06
mveDave Kreskowiak27-Jul-04 3:06 
GeneralXML Serialization of a Recursive Custom Collection Pin
Michael R. Rich25-Jul-04 19:20
Michael R. Rich25-Jul-04 19:20 
GeneralClass Library references Pin
beowulfagate25-Jul-04 18:29
beowulfagate25-Jul-04 18:29 
GeneralRe: Class Library references Pin
sukesh.g25-Jul-04 20:24
sukesh.g25-Jul-04 20:24 
GeneralRe: Class Library references Pin
Dave Kreskowiak26-Jul-04 6:36
mveDave Kreskowiak26-Jul-04 6:36 
GeneralRe: Class Library references Pin
beowulfagate26-Jul-04 17:48
beowulfagate26-Jul-04 17:48 
GeneralVB 6 autoupdating combo Pin
axel_wing25-Jul-04 3:01
axel_wing25-Jul-04 3:01 
GeneralRe: VB 6 autoupdating combo Pin
Roger Wright25-Jul-04 4:59
professionalRoger Wright25-Jul-04 4:59 
GeneralRe: VB 6 autoupdating combo Pin
axel_wing25-Jul-04 5:13
axel_wing25-Jul-04 5:13 
GeneralApplication Task Bar Pin
Michael R. Rich24-Jul-04 20:14
Michael R. Rich24-Jul-04 20:14 
GeneralRe: Application Task Bar Pin
progload25-Jul-04 6:07
progload25-Jul-04 6:07 
GeneralRe: Application Task Bar Pin
Michael R. Rich25-Jul-04 12:55
Michael R. Rich25-Jul-04 12:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.