Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Digitize Part of Bitmap Image


Digitize Part of Bitmap Image

Author
Message
La Vesey
La Vesey
Forum God
Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)

Group: Forum Members
Posts: 12, Visits: 49
I am a raw beginner to visual basic (I have ver. 6), I do have some experience with quickbasic 4.5 which is not visual.

I need code to open a large bitmap image in JPG format, size is 2300 by 2697 pix and my screen size is 1024 by 768, placing it on a background ( or layer), which will not be saved. Then on an active layer I want to draw parts of this bitmap image in as points (nodes) and lines, or ploylines, and when done, save this vector data (layer).

Then I want to export or save this vector data to a file in plain text.



Looks like what I need to do is write code for a "picture box" in order to load (open) the jpg bitmat, --- then ---



write code for recording (appending) the screen coordinates of each mouse click, to an ascii text file.



I have read general books for V B but it appears they are assuming that I already know what is going on, which I do not.



There are commercial programs which will do this, but they are very expensive, and the beauty of writing my own is that I have some control over how it works.

La Vesey

vb5prgrmr
vb5prgrmr
Forum God
Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)

Group: Forum Members
Posts: 167, Visits: 786
Okay, to load a picture into a picture box, image control, or stdPicture object, you can use the LoadPicture Function. Now, the reason I mentioned the stdPicture object is because it uses less memory than the two controls I mentioned and since you picture is larger than your screen, you will need to do one of two different things.

If you use a picturebox control and set its autosize property to true, you will need to use scrollbars to change the left/top properties of the picture box.

If you use a stdPicture or a hidden picture box and "render" portions of the image to the picture box, you will have to keep track of what portion you rendered and compute those values with the position of where the user clicked.

 

Good Luck

vb5prgrmr
vb5prgrmr
Forum God
Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)

Group: Forum Members
Posts: 167, Visits: 786
Okay, recieved your email...

>  Picture1.Height = 550* 1440  ' this may not be needed

>  Picture1.Width = 750 * 1440

>      Z = 800  'elev. value

>   Open "d:\cont-800.dat" for append as #2

>  Picture1.Picture = LoadPicture("d:\map17.jpg")' input image

>    ' begin loop

>      Private Sub MouseDown( X as integer, Y as integer)

>        Print #2, X, Y, Z;

>        End Sub

>    ' end loop

>      close #2 : end

>

> NOTES: I am SURE it can NOT be this simple!!! but Chrome plate not needed!

>

> 1. Since I will not be clicking anywhere except inside the picture box

>     Image, I do not see that I need any Control buttons ?

>

> 2. What is a good way to end the loop? when right mouse is clicked?

>    or control break, or escape?  I could use a counter, but no two

>    maps will be the same. Also best way to start loop?

>

> 3. Is it necessary to "associate" the sub with the picture box?

>

> 4. I presume that if the bitmap image is larger than the screen, and

>    they will be, that it will create schroll bars?

>

> ----end----

How you got it is of no great concern but that you used it instead of posting here is, as I may have missed other emails from people I do not recognize....

Okay, back to the problem...

Start a new standard exe project. Add a Picture box and name it Pic. Add a vertical Scroll bar and name it VS. Add a horizontal scroll bar and name it HS. Add the code and don't forget to change the path of the picture to be loaded...

Option Explicit

Private Sub Form_Load()
Me.ScaleMode = vbPixels
Me.AutoRedraw = True
Pic.ScaleMode = vbPixels
Pic.AutoRedraw = True
HS.Move 1, Me.ScaleHeight - (HS.Height), Me.ScaleWidth
VS.Move Me.ScaleWidth - (VS.Width), 0, VS.Width, Me.ScaleHeight - (HS.Height)
Pic.Move 0, 0
Pic.AutoSize = True

'where ever you have this load picture function, you need to have your open file statement(s)
Pic.Picture = LoadPicture("path to jpeg here")
HS.ZOrder 0
VS.ZOrder 0

HS.Max = (Pic.Width - Me.ScaleWidth)
HS.LargeChange = HS.Max / 10

VS.Max = (Pic.Height - Me.ScaleHeight)
VS.LargeChange = VS.Max / 10

End Sub

Private Sub HS_Change()
Pic.Left = (-1 * HS.Value)
End Sub

Private Sub VS_Change()
Pic.Top = (-1 * VS.Value)
End Sub

Private Sub Pic_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'depending upon what you want to do, you could use all three of these events
End Sub

Private Sub Pic_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'depending upon what you want to do, you could use all three of these events
End Sub

Private Sub Pic_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'depending upon what you want to do, you could use all three of these events
End Sub

Good Luck

Edited
7/17/2010 by vb5prgrmr
vb5prgrmr
vb5prgrmr
Forum God
Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)

Group: Forum Members
Posts: 167, Visits: 786
Once again... Please post your questions within this forum!!!


TO: vb5prgrmr, 7-22-10

Thanks for your reply to my email and the code you sent.

1. I suspect you somewhat forgot my primary purpose in this little project.

Which was to record, that is, write out in ascii plain text format the screen
coordinates, the X & Y,  of the mouseDOWN clicks to a file. That is why I opened
the outfile in append mode.

So I do not see why I need mouseUP or mouseMOVE. But I think I do need a loop
for each point, which I will select its location manually on the screen in the
bitmap image.

Okay then, don't use the other two events...


2. I prefer NOT to scale the bitmap to fit, as that would make it smaller and
reduce the accuracy or the points. The image will be larger than the screen, so
that means I will need  Horiz and Vert scroll bars. My compiler is vb ver. 6,
which I am sure is compatible with ver. 5.

See previous post as I already answered that...


3. Also it would be good to change the mouse curser to a crosshair, as that
would make the point more accruate.

Check out both the MouseIcon and MousePointer Properties in the help files (Especially the MousePointer Property Smile)

4. It also would be good to print the X & Y of the current point to the screen,
say in the lower right corner, Just to see exactly what is happening.

Use the MouseDown Event to capture this data and to record your x/y points.

5. Below us my original post for review.

----------------------------------------

Posted 4/27/2010 12:18:23 PM   

Forum Newbie

Group: Forum Members

Last Login: 7/14/2010 11:54:43 AM

Posts: 1, Visits: 19

I am a raw beginner to visual basic (I have ver. 6), I do have some experience
with quickbasic 4.5 which is not visual.

I need code to open a large bitmap image in JPG format, size is 2300 by 2697 pix
and my screen size is 1024 by 768, placing it on a background ( or layer), which
will not be saved. Then on an active layer I want to draw parts of this bitmap
image in as points (nodes) and lines, or ploylines, and when done, save this
vector data (layer).

Then I want to export or save this vector data to a file in plain text.

Looks like what I need to do is write code for a "picture box" in order to load
(open) the jpg bitmat, --- then ---

write code for recording (appending) the screen coordinates of each mouse click,
to an ascii text file.

I have read general books for V B but it appears they are assuming that I
already know what is going on, which I do not.

There are commercial programs which will do this, but they are very expensive,
and the beauty of writing my own is that I have some control over how it works.

La Vesey

So please, post your questions here so I can stop quoting your emails. I stop by this site at least once a day...

Okay, some other things to look up on the web or in VB's help files.
Dynamic arrays

Why dynamic arrays, because as the mouse down event happens, you would redimension your dynamic array +1 and then record the x/y values. Then when you want to save the informaiton to your text file, you would go from lbound to ubound of your array and once that was done, you would reset your arrays...

 

Good Luck

La Vesey
La Vesey
Forum God
Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)

Group: Forum Members
Posts: 12, Visits: 49
TO: vb5prgrmr, 7-24-10



Thanks again, for your answers.



Don't forget - Although I have written may QB45 programs, I have never written a VB program, although I have read parts of many book. Most of it is OVER my head!



You said:

Okay, some other things to look up on the web or in VB's help files.

Dynamic arrays



Why dynamic arrays, because as the mouse down event happens, you would redimension your dynamic array +1 and then record the x/y values. Then when you want to save the informaiton to your text file, you would go from lbound to ubound of your array and once that was done, you would reset your arrays...



My reply:

The redimension my dynamic arrays is a bit over my head.



I suspect you want to store the x & Y values in memory, UNTIL they are done for this image, THEN write them out to a file, right?



While I will accept and try any method that will work, - My suggested method is simpler as it would write the X & Y values directly to the output file immediately after it was sorted, right?

In this case I would need some sort of a loop to repeat the process for the next point? your method, may not need the loop as you want to write them all to the file after all points are stored, correct?



Your method would also require that I write the code necessary to set up the array, whereas my simpleton method would not need such code to setup the array, is this correct?



Did your previous replies show a simple method to write the code for the Horiz. and Vertical scholl bars?



Thanks again for your willingness to help!



As you can see I am going to need much more than Luck!

La Vesey







La Vesey
La Vesey
Forum God
Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)

Group: Forum Members
Posts: 12, Visits: 49


Since you have not responded to my last reply of 7-24,

I guess you have given up on me, because I am almost totally ignorant of Visual Basic, correct?



Again thanks for your attempts to help!

La Vesey



P.S. in my last reply the term "sorted" should have been stored (written to a file).

La Vesey
La Vesey
Forum God
Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)

Group: Forum Members
Posts: 12, Visits: 49
I have not been able to locate the original and updates for Microsoft Visual Basic 6.0 ---help---files.



Even on msdn I did find a tutorial, but no help files. In my searching some users are saying that the original help files are one cds 2 and 3 which I do not have. They say it is a 50 mb file which is no problem for the T1 connection at my local library.



So where can I find these files or file?

Thanks in advance for your help!

La Vesey





Keithuk
Keithuk
Forum God
Forum God (297K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
La Vesey (8/4/2010)
I have not been able to locate the original and updates for Microsoft Visual Basic 6.0 ---help---files.

Even on msdn I did find a tutorial, but no help files. In my searching some users are saying that the original help files are one cds 2 and 3 which I do not have. 

If you have the MSDN Library CD's 1 & 2 then you should be able to install the VB help. Have a look in Control Panel - Add/Remove or Programs and Features for MSDN Library - Visual Studio 6.0a to see if its installed?

Open up VB with a new or existing project then just press F1 the help should show. If it doesn't then remove it from Add/Remove and reinstall it. Wink

Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Keithuk
Keithuk
Forum God
Forum God (297K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
vb5prgrmr - I though you would have realised by now that you can display the VB better on this forum if you use Mark's Syntax.zip
Option Explicit

Private Sub Form_Load()
Me.ScaleMode = vbPixels
Me.AutoRedraw = True
Pic.ScaleMode = vbPixels
Pic.AutoRedraw = True
HS.Move 1, Me.ScaleHeight - (HS.Height), Me.ScaleWidth
VS.Move Me.ScaleWidth - (VS.Width), 0, VS.Width, Me.ScaleHeight - (HS.Height)
Pic.Move 0, 0
Pic.AutoSize = True

'where ever you have this load picture function, you need to have your open file statement(s)
Pic.Picture = LoadPicture("path to jpeg here")
HS.ZOrder 0
VS.ZOrder 0

HS.Max = (Pic.Width - Me.ScaleWidth)
HS.LargeChange = HS.Max / 10

VS.Max = (Pic.Height - Me.ScaleHeight)
VS.LargeChange = VS.Max / 10

End Sub

Private Sub HS_Change()
Pic.Left = (-1 * HS.Value)
End Sub

Private Sub VS_Change()
Pic.Top = (-1 * VS.Value)
End Sub

Private Sub Pic_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'depending upon what you want to do, you could use all three of these events
End Sub

Private Sub Pic_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'depending upon what you want to do, you could use all three of these events
End Sub

Private Sub Pic_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'depending upon what you want to do, you could use all three of these events
End Sub




Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

La Vesey
La Vesey
Forum God
Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)Forum God (3.6K reputation)

Group: Forum Members
Posts: 12, Visits: 49
Keithk, 8-5-10



Thanks very much for your post in reply to my stuff.



Perhaps you can help with my second primary loop (if I need a loop), which is the writing out of the of X & Y screen coordinates (from inside the bitmap image only) of the MouseDown event, I don't see why i need UP and MOVE.



here was my first feeble attempt:



Open "d:\cont-800.dat" for append as #2

z = 800 (this will need to be changed during the process)



begin loop (if I need a loop)



> Private Sub MouseDown( X as integer, Y as integer)



> Print #2, X, Y, Z;



> End Sub



> ' end loop



> close #2 : end



If each point is written out as soon as it is stored, then no need for a memory array to store the points untill done, right? Why do I need a Button?



If I need a loop, then what is the simplist way to end the loop, InKey maybe? Or click outside the bitmap image? Enter a control break?



Again, thanks for your interest and help!

La Vesey





GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search