-
May 7th, 2012, 12:27 PM
#1
Thread Starter
New Member
vb code to create a image file.
Hi all,,,,,,,,,
Plzzzzzzz help me with the vb code to create a image file say(.jpg/.gif/.bmp) files....
I have a code which would create text/word/excel files .....But I tried this code to create an image file....But I couldn't make it.....Though the file is created but i am unable to view it.....
Plz...............help me this out..........
The code is as follows...
Public Sub veeru()
Const FILENAME = "C:\Users\310314\Desktop\myfile.xls"
Dim My_filenumber As Integer
My_filenumber = FreeFile
Open FILENAME For Output As #My_filenumber
Write #My_filenumber, "Hello"
Close #My_filenumber
End Sub
-
May 7th, 2012, 01:28 PM
#2
Re: vb code to create a image file.
You cannot just make a text file and save it as a .bmp and expect it to be an image file. You need a valid image. I'm not sure what you mean by making an image file. You can load an existing image file into your VB app and then save it as another name. You can put a Picturebox control on your Form and write some code to draw on it and then save what you drew as a .bmp file. Is this what you want to do?
Last edited by jmsrickland; May 7th, 2012 at 01:51 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 7th, 2012, 04:23 PM
#3
Re: vb code to create a image file.
Originally Posted by jmsrickland
You cannot just make a text file and save it as a .bmp and expect it to be an image file.
True, but he can open it in notepad and press print-screen!
-
May 7th, 2012, 06:40 PM
#4
Re: vb code to create a image file.
start new project and add to you form code:
vb Code:
Private WithEvents Timer1 As VB.Timer
Private PictureBox1 As PictureBox
Private Sub Form_Load()
Dim X1 As Single
Dim X2 As Single
Dim Y1 As Single
Dim Y2 As Single
Set Timer1 = Controls.Add("VB.Timer", "Timer1")
Set PictureBox1 = Controls.Add("VB.PictureBox", "PictureBox1")
With PictureBox1
.Left = 0
.Top = 0
.Width = 4000
.Height = 4000
.AutoRedraw = True
.DrawWidth = 4
.Visible = True
End With
With Me
.Width = 5000
.Height = 5000
.BorderStyle = 5
.Caption = "Drawing..."
End With
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static LineNumber As Integer
Dim MsgBoxResponse As Integer
Dim PictureName As String
LineNumber = LineNumber + 1
Select Case LineNumber
Case 1
X1 = 100
X2 = 2000
Y1 = 100
Y2 = 100
PictureBox1.Line (X1, Y1)-(X2, Y2), vbRed
Case 2
X1 = 100
X2 = 100
Y1 = 100
Y2 = 2000
PictureBox1.Line (X1, Y1)-(X2, Y2), vbBlue
Case 3
X1 = 2000
X2 = 2000
Y1 = 100
Y2 = 2000
PictureBox1.Line (X1, Y1)-(X2, Y2), vbGreen
Case 4
X1 = 100
X2 = 2000
Y1 = 2000
Y2 = 2000
PictureBox1.Line (X1, Y1)-(X2, Y2), vbBlack
Case 5
X1 = 100
X2 = 2000
Y1 = 100
Y2 = 2000
PictureBox1.Line (X1, Y1)-(X2, Y2), vbCyan
Case 6
X1 = 100
X2 = 2000
Y1 = 2000
Y2 = 100
PictureBox1.Line (X1, Y1)-(X2, Y2), vbWhite
Me.Caption = "Save Picture?"
Case 7
Timer1.Enabled = False
MsgBoxResponse = MsgBox("Would you like to save current picture?", vbYesNo + vbExclamation, "Save picture?")
Select Case MsgBoxResponse
Case vbYes
PictureName = InputBox("Enter your picture name please.", "Saving Picture As", "Picture1")
SavePicture PictureBox1.Image, App.Path & "\" & PictureName & ".bmp"
Me.Caption = "User Saved Picture"
Shell "Explorer.exe " & App.Path, vbNormalFocus
Shell "msPaint.exe " & Chr(34) & App.Path & "\" & PictureName & ".bmp" & Chr(34), vbNormalFocus
Case vbNo
Me.Caption = "User did not save picture!"
End Select
End Select
End Sub
Edit: In other words all i need to make image file is
SavePicture PictureBox1.Image, App.Path & "\Picture1.bmp"
Last edited by Max187Boucher; May 7th, 2012 at 07:01 PM.
-
May 8th, 2012, 10:13 AM
#5
Thread Starter
New Member
Re: vb code to create a image file.
Thanks Max187Boucher that was nice.....
But instead my suggestion is like I just want to create an image file of any format say (bmp/jpg/gif).......
I dont mind on the content in it......It is not necessary that it has to be some picture......It can be a image file that has a paragraph of text(This would be awesome if it is possible).....
And finally I dont wanna to prompt the user a dialog bow for saving.....It can directly save it to the path which I mention......
And if it could make the copy of this finally created image file to 'n' number of image files then that would be great...............
Can you help me with your suggestions.......
-
May 8th, 2012, 11:59 AM
#6
Re: vb code to create a image file.
I think his code example told you how to do that. I told you in post #2 to put a Picturebox on your Form , draw in it, and then save it as a .bmp file. His code shows you how to put a Picturebox on your Form, draw some lines, and then save it as a .bmp file. Instead of drawing lines just Print your text in it. What else do you want to know?
Code:
'
'
Picture1.CurrentX = 10
Picture1.CurrentY = 10
Picture1.Print "HELLO"
SavePicture PictureBox1.Image, App.Path & "\" & PictureName & ".bmp"
'
'
Last edited by jmsrickland; May 8th, 2012 at 12:11 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|