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
Quote:
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?
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.
Re: How to save a stdPicture that is an UDT field
I'm not sure if I've understood well :confused:
What are the steps I should do?
Re: How to save a stdPicture that is an UDT field
What aspect are you unclear about?
Re: How to save a stdPicture that is an UDT field
Honestly I've had some troubles during the translation from English to Italian :blush:
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?
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?
Re: How to save a stdPicture that is an UDT field
Quote:
Originally Posted by
DataMiser
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) ?
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,
:wave:
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
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 ;)
:wave:
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?
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?