Results 1 to 6 of 6

Thread: vb code to create a image file.

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    6

    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

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  3. #3
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: vb code to create a image file.

    Quote Originally Posted by jmsrickland View Post
    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!

  4. #4
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: vb code to create a image file.

    start new project and add to you form code:

    vb Code:
    1. Private WithEvents Timer1 As VB.Timer
    2.  
    3. Private PictureBox1 As PictureBox
    4.  
    5.  
    6. Private Sub Form_Load()
    7. Dim X1 As Single
    8. Dim X2 As Single
    9. Dim Y1 As Single
    10. Dim Y2 As Single
    11.  
    12. Set Timer1 = Controls.Add("VB.Timer", "Timer1")
    13. Set PictureBox1 = Controls.Add("VB.PictureBox", "PictureBox1")
    14.  
    15. With PictureBox1
    16.    .Left = 0
    17.    .Top = 0
    18.    .Width = 4000
    19.    .Height = 4000
    20.    .AutoRedraw = True
    21.    .DrawWidth = 4
    22.    .Visible = True
    23. End With
    24.  
    25. With Me
    26.    .Width = 5000
    27.    .Height = 5000
    28.    .BorderStyle = 5
    29.    .Caption = "Drawing..."
    30. End With
    31.  
    32. Timer1.Interval = 500
    33. Timer1.Enabled = True
    34. End Sub
    35.  
    36.  
    37. Private Sub Timer1_Timer()
    38. Static LineNumber As Integer
    39. Dim MsgBoxResponse As Integer
    40. Dim PictureName As String
    41.  
    42. LineNumber = LineNumber + 1
    43.  
    44. Select Case LineNumber
    45.  
    46.    Case 1
    47.       X1 = 100
    48.       X2 = 2000
    49.       Y1 = 100
    50.       Y2 = 100
    51.       PictureBox1.Line (X1, Y1)-(X2, Y2), vbRed
    52.  
    53.    Case 2
    54.       X1 = 100
    55.       X2 = 100
    56.       Y1 = 100
    57.       Y2 = 2000
    58.       PictureBox1.Line (X1, Y1)-(X2, Y2), vbBlue
    59.    
    60.    Case 3
    61.       X1 = 2000
    62.       X2 = 2000
    63.       Y1 = 100
    64.       Y2 = 2000
    65.       PictureBox1.Line (X1, Y1)-(X2, Y2), vbGreen
    66.  
    67.    Case 4
    68.       X1 = 100
    69.       X2 = 2000
    70.       Y1 = 2000
    71.       Y2 = 2000
    72.       PictureBox1.Line (X1, Y1)-(X2, Y2), vbBlack
    73.      
    74.    Case 5
    75.       X1 = 100
    76.       X2 = 2000
    77.       Y1 = 100
    78.       Y2 = 2000
    79.       PictureBox1.Line (X1, Y1)-(X2, Y2), vbCyan
    80.    
    81.    Case 6
    82.       X1 = 100
    83.       X2 = 2000
    84.       Y1 = 2000
    85.       Y2 = 100
    86.       PictureBox1.Line (X1, Y1)-(X2, Y2), vbWhite
    87.       Me.Caption = "Save Picture?"
    88.      
    89.    Case 7
    90.       Timer1.Enabled = False
    91.       MsgBoxResponse = MsgBox("Would you like to save current picture?", vbYesNo + vbExclamation, "Save picture?")
    92.  
    93.          Select Case MsgBoxResponse
    94.          
    95.             Case vbYes
    96.                PictureName = InputBox("Enter your picture name please.", "Saving Picture As", "Picture1")
    97.                SavePicture PictureBox1.Image, App.Path & "\" & PictureName & ".bmp"
    98.                Me.Caption = "User Saved Picture"
    99.                Shell "Explorer.exe " & App.Path, vbNormalFocus
    100.                Shell "msPaint.exe " & Chr(34) & App.Path & "\" & PictureName & ".bmp" & Chr(34), vbNormalFocus
    101.  
    102.                
    103.             Case vbNo
    104.                Me.Caption = "User did not save picture!"
    105.          End Select
    106. End Select
    107. 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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    6

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

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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
  •  



Click Here to Expand Forum to Full Width