How to save a stdPicture that is an UDT field
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: How to save a stdPicture that is an UDT field

Hybrid View

  1. #1
    Join Date
    Dec 2012
    Posts
    38

    How to save a stdPicture that is an UDT field

    Good morning

    I've an UDT within a stdPicture field. When I try to run the code to save the structure into a file, VB raises a compilation error
    You cannot use Put or Get with pointers to an object or with user defined types that contains a pointer to an object
    What should I do?

  2. #2
    Join Date
    Dec 2001
    Posts
    6,332

    Re: How to save a stdPicture that is an UDT field

    There are a few options. One way involves using a Byte array to hold the image data within the UDT. Converting the array into a stdPicture object when loading the previously saved file can be accomplished a few ways as well. Or, it is also possible to copy the data directly into a memory Bitmap. The methods you choose should depend on your level of skill.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  3. #3
    Join Date
    Dec 2012
    Posts
    38

    Re: How to save a stdPicture that is an UDT field

    I'm not sure if I've understood well

    What are the steps I should do?

  4. #4
    Join Date
    Dec 2001
    Posts
    6,332

    Re: How to save a stdPicture that is an UDT field

    What aspect are you unclear about?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  5. #5
    Join Date
    Dec 2012
    Posts
    38

    Re: How to save a stdPicture that is an UDT field

    Honestly I've had some troubles during the translation from English to Italian

    Now reading again I think I've understood, but however I don't know how to do.

    Code:
        Dim arr() As Byte
        
        ReDim arr(FileLen("C:\tramonto.jpg")) As Byte
        Open "C:\tramonto.jpg" For Binary As #1
        Get #1, , arr()
        Close #1
    With the code above I hold the image into an array of bytes. Now, what have I to do?
    Last edited by Cereal Killer; March 5th, 2013 at 10:18 AM.

  6. #6
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,845

    Re: How to save a stdPicture that is an UDT field

    Not sure I understand what the question is. In the title it asks how to save the data but the code just posted is reading the data from file meaning it is already saved.

    What is it that you are actually trying to do?
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Dec 2012
    Posts
    38

    Re: How to save a stdPicture that is an UDT field

    Quote Originally Posted by DataMiser View Post
    Not sure I understand what the question is. In the title it asks how to save the data but the code just posted is reading the data from file meaning it is already saved. What is it that you are actually trying to do?
    I have a form within a PictureBox object where the user clicks on it and will appear a CommonDialog to choose what image will be loaded into the control. The PictureBox needs to show the image only, because the data are saved into a stdPicture class, that is a field of an UDT.

    Once the image is chosen, I need that it is saved within the UDT into a file from which I'll get data next time my application will start. I tried to use the PUT statement to save the UDT into the file, but VB doesn't let me to do that. So I asked here what I should have to do.

    WizBang suggested me to manage the picture as an array of bytes, and not like an object (or this is what I understood). The code I posted is what I've to do to load data from the original picture file ready to be saved into my file. A similar process is done when I attempt to get data from my file using the GET statement.

    The question is: now that I have the picture loaded into the array, how do I set it to my PictureBox (or to a stdPicture object, that's the same) ?

  8. #8
    Join Date
    Dec 2012
    Posts
    38

    Re: How to save a stdPicture that is an UDT field

    Hello folks

    Meanwhile I was waiting anyone who replies, I did a research and I discovered this interesting link vb6-MP3-WMA-Image-Extraction. I took the part I need and it seems to work well for my own purposes. If anyone has other suggestions to give, I'll be glad to listen to them

    However thanks for your attention,

  9. #9
    Join Date
    Dec 2001
    Posts
    6,332

    Re: How to save a stdPicture that is an UDT field

    Glad to see you found something that works for you. Here is another of essentially the same method, for your comparison. I haven't looked it over, but in the past I've seen such examples which have memory leaks. Hopefully the function you end up using will be complete. http://www.tek-tips.com/viewthread.cfm?qid=1541026
    Last edited by WizBang; March 6th, 2013 at 02:19 PM.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  10. #10
    Join Date
    Dec 2012
    Posts
    38

    Re: How to save a stdPicture that is an UDT field

    Thank you so much I'll give it a look as soon as is possible


  11. #11
    Join Date
    Dec 2012
    Posts
    38

    Re: How to save a stdPicture that is an UDT field

    I need to your help again

    Once I loaded a picture into a stdPicture object using LoadPicture function, how can I convert data from the stdPicture object into a ByteArray?

  12. #12
    Join Date
    Dec 2001
    Posts
    6,332

    Re: How to save a stdPicture that is an UDT field

    As with most things, there are a few ways to get a Byte array of the image in an stdPicture object (or PictureBox).

    Here's an example:
    http://stackoverflow.com/questions/2...e-array-in-vb6

    However, if you already have the file, why not use it directly?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center