Results 1 to 8 of 8

Thread: Bitmaps & INIs: Newbie Qestions

  1. #1

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Bitmaps & INIs: Newbie Qestions

    I'm a total beginner in VB programming, and critically need two functions for a small program I'm writing. First would be how to resize or at least crop Bitmaps(as a file). And the second one, although not as crucial, is how would I go about modifying an existing INI file, or to be exact replacing a preset integer value with a constant(0).

    Thanx in advance.

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Bitmaps & INIs: Newbie Qestions

    Planet Source Code helps with your bitmap problem. Also, you can use LoadPicture and SavePicture to load and save pictures.

  3. #3

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Bitmaps & INIs: Newbie Qestions

    Thanx a lot. What about the second question?

  4. #4
    Addicted Member Luke K's Avatar
    Join Date
    Jun 2004
    Location
    Perth, Australia
    Posts
    183

    Re: Bitmaps & INIs: Newbie Qestions

    INI Manipulation is very easy with two simply API, or 3, depending on what type of data you are manipulating. You said you were using integers, so this should do fine

    VB Code:
    1. Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
    2. Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    3.  
    4. Private Sub Command1_Click()
    5.  
    6.     Call WritePrivateProfileString("SECTION", "KEY", "45", "C:\test.ini")
    7.     MsgBox GetPrivateProfileInt("SECTION", "KEY", 0, "C:\test.ini")
    8.    
    9.     'now view the ini file and see how it is structured in code.
    10.     'If you want to read a string from the ini file, you will have to use
    11.     'the GetPrivateProfileString api instead of GetPrivateProfileInt
    12.  
    13. End Sub
    Artificial Intelligence At War! - The best game of its genre
    Program your own robot and watch it fight in 3d!
    Droidarena 3

    If I have been useful, please Rate My Post

    Support FireFox -
    Microsoft Visual Studio .NET Professional 2003
    Microsoft Visual Studio 6, Enterprise Edition
    Microsoft Windows XP Professional, Service Pack 2

  5. #5

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Bitmaps & INIs: Newbie Qestions

    Mucho Gracias! Now, sorry if I'm going offtopic :blush:, but I've 2 more questions... Is it possible to detect a creation of file(created by another program) and trigger an event when it happens? Or detect a keystroke when the another (full-screen) program has the focus(it may be of significance that the other program detects it as well)?

    Let me explain the concept of what I'm doing. It's a mod for a video game. Mainly, I want the player to be able to make photos ingame. This proggy I'm writing handles the detection of taking a screnshot(pressing the PrntScrn button), then copies the file that is created to another folder and resizes/crops it. Then the ingame scripting engine kicks in, makes a mesh, and applies the file copied by the program as a texture. The ingame scripting isn't of any difficulty to me, but it doesn't handle file-management like that, so I had to write that part externally, and since the only language I at least have a clue about is VB...

    Oh, and I've found this bit of code on Planet Source Code for resizing bitmaps:

    Code:
    Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
            
    Declare Function BitBlt Lib "gdi32" (ByVal hDestDC%, ByVal X%, ByVal Y%, ByVal nWidth%, ByVal nHeight%, ByVal hSrcDC%, ByVal xSrc%, ByVal ySrc%, ByVal dwRop&) As Integer
    But the author mentions that the color pallette has to be reduced to 256 if using this function, and unfortunately this is not acceptable in this case, plus I'm not exactly sure what they mean by some of the vars... So, would anyone be kind enough as to give another way to do this?

  6. #6

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Bitmaps & INIs: Newbie Qestions

    Sorry to bump, but I really need it. The bitmap resizing part.

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Bitmaps & INIs: Newbie Qestions

    can you use the picturebox resize property?

  8. #8

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Bitmaps & INIs: Newbie Qestions

    What do you mean? There's a resize event for a PBox, but it just registers the resize of the control. What I need is open a Bitmap, resize it, and save with the new size, and there's no property for the PBox that does that AFAIK.

    Oh, and what's wrong with this:

    VB Code:
    1. Call SavePicture(Picture2.Picture, "D:\max_tx_photo_2.bmp")

    The picture exists, and the drive as well. But it gives me an "Invalid Property Value" error...

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