|
Bitmap charts in an UDT Array |
Posted by Daniel on May-28-2014 23:27 |
|
Hi Peter,
In your demo you created a tree view with all main charts included in ChartDirector library.
For this purpose you have used a collection both to store the charts name and to call
certain charts from classes. Keeping your idea, I created an app with a tree view and
a collection but besides I stored all charts from begining in an UDT array as follow:
Public Type ArrayUDT 'array of arrays
arrElements() As Byte
End Type
Public greatArray() As ArrayUDT
Private q As Byte
Public Sub myUDT(byteArr() As Byte)
q = q + 1
greatArray(q).arrElements = byteArr
End Sub
For the UDT array loading I used in each class:
Dim B() As Byte
B = c.makeChart2(cd.bmp)
Call myUDT(B)
In this way I get in a fast way an array of byte arrays with all charts I am interested in.
Now, the idea is I would like to display the charts from this array directly once the
NodeClick event is fired and to avoid to re-run the class chart each time a node is selected.
Do you think it is possible to display the stored charts from this array ? For example,
greatArray(2).arrElements has stored the second chart as byte array but now I would like
to display it on the view...Is it any method to do it ? Thank you. |
Re: Bitmap charts in an UDT Array |
Posted by Peter Kwan on May-29-2014 02:16 |
|
Hi Daniel,
If the intention of the ArrayUDT is to speed up the display of charts on the screen, you may
use an array of Picture object instead of an array of bytes. It is because VB6 cannot handle
images directly. They must be loaded into Picture objects for them to be useful to VB6. It is
like:
Public Type ArrayUDT 'array of arrays
arrElements() As Picture
End Type
Then you can store the output of c.makePicture() (which is a Picture object) into the array.
When you need to display the chart, you can set the Picture object to the ChartViewer.
Hope this can help.
Regards
Peter Kwan |
Re: Bitmap charts in an UDT Array |
Posted by Daniel on May-29-2014 02:36 |
|
Thank you for this quick reply. My intention is both to display the charts on a picture (to
see if everything was displayed properly inside of the chart) and after that to transfer these
charts - via clipboard - in some ppt slides. As you know ChartDirector has no dedicated
method to transfer its images (charts) to other environments directly and for this reason I
have to transfer the charts as byte array. Now I do not know if it will be possible to
transfer the charts in a similar way (Clipboard) declaring arrElements() As Picture ...
Besides this, could you be more clear how to "set the Picture object to the ChartViewer" ?
Thank you. |
Re: Bitmap charts in an UDT Array |
Posted by Peter Kwan on May-29-2014 15:43 |
|
Hi Daniel,
I assume you are writing a VB6 (or VBA) program. In this type of development
environment, normally the chart image is displayed using something like:
Set myChartViewerObject.Picture = c.makePicture()
The myChartViewerObject can be a ChartDirector ChartViewer control. Most other VB6
controls also accept the Picture object, such as the PictureBox control, the Form itself,
the CommandButton control, etc.. The Picture object is the standard method to
"transfer" images to other environments in VB6. In particular, the VB6 Clipboard object
also supports the Picture object.
So if you have stored the Picture object in the array, you can display it using:
Set myChartViewerObject.Picture = greatArray(index).myPicture
and you can copy it to the clipboard using:
Clipboard.setData greatArray(index).myPicture
On the other hand, VB6 cannot use BMP directly. The VB6 Clipboard object does not
support BMP directly, and you cannot display BMP directly in any VB6 controls. The BMP
has to be convert to a Picture object first (eg. using the VB6 LoadPicture function). So
you may want to just directly store the Picture object.
Hope this can help.
Regards
Peter Kwan |
Re: Bitmap charts in an UDT Array |
Posted by Daniel on May-29-2014 17:19 |
|
Hi Peter,
Thank you for reply. Yes I use VB6, one of the best languages ever created (place 5 in the
TIOBE hierarchy on May this year). Idea is you cannot declare an UDT array as picture but
as picturebox as below :
Public Type ArrayUDT 'array of arrays
arrElements() As PictureBox
End Type
Public greatArray() As ArrayUDT
After that, you cannot load the charts in a UDT array as you suggested above
greatArray(index).arrElements = c.makePicture(). It doesn't work. Actually, I do not
understand very well what you suggested because you didn't write a code line as solution.
When you say "you cannot display BMP directly in any VB6 controls" I think you mean we
do not have any vb6 native method to do this. Otherwise, I have already managed to use
some API functions to load a PictureBox from a byte array directly.
So, the question is how to load the array with a chart picture :
greatArray(index).arrElements = ?
Regards,
Daniel |
Re: Bitmap charts in an UDT Array |
Posted by Peter Kwan on May-29-2014 22:18 |
|
Hi Daniel,
Sorry, it should be:
Type ArrayUDT
arrElement As Picture
End Type
Dim greatArray() As ArrayUDT
It is an array of Picture objects, not an array of array of Picture objects.
I have just tried the following code, and it works normally.
ReDim greatArray(10)
'Save the Picture object
Set greatArray(0).arrElement = c.makePicture()
'Transfer the Picture object to the ChartViewer
Set ChartViewer.Picture = greatArray(0).arrElement
If you encounter any issue, please let me know what is the error message.
Hope this can help.
Regards
Peter Kwan |
Re: Bitmap charts in an UDT Array |
Posted by Daniel on May-29-2014 22:42 |
|
Hi Peter,
The line suggested - Set greatArray(1).arrElement = c.makePicture() - doesn't work.
I get the error displayed below. On the other hand I do not see any object in IDE named
Picture but PictureBox only ...Why have you declared again as Picture ?
Type ArrayUDT
arrElement As Picture
End Type
Dim greatArray() As ArrayUDT
Have you ever tested something like this or is it just a supposition ? I have never seen a
reference created to an array as you did above ... Set greatArray(1).arrElement. Please
note the IDE is VB6. Thank you
|
Re: Bitmap charts in an UDT Array |
Posted by Daniel on May-29-2014 22:57 |
|
I am sorry, the compile error above is other : "Can't assign to Array".
By the way, what do want to say in that sentence: "It is an array of Picture objects, not
an array of array of Picture objects." ?? |
Re: Bitmap charts in an UDT Array |
Posted by Peter Kwan on May-30-2014 02:36 |
|
Hi Daniel,
The "Method or Data member not found" error usually means there is a spelling mistake in
the member name. For example, the Type can be defined as using arrElements as the
name, but the actual code is using arrElement (note the different spelling).
The "Can't assign to Array" usually means that your code is assigned a scalar variable to
an array. For example, your code is using:
arrElements() As Picture
then it would cause this error. It should be:
arrElement As Picture
If you use
Type ArrayUDT
arrElement As Picture
End Type
Dim greatArray() As ArrayUDT
then it is an array of array of Picture objects. It is because greatArray is an array. In
each element of the greatArray, it contains another array called arrElements. Each of the
elements of the arrElements is a Picture object. So there is an array of array of Picture
objects.
Instead, the type definition should be:
Type ArrayUDT
arrElement As Picture
End Type
Dim greatArray() As ArrayUDT
The greatArray is an array, and each element of the array contains one Picture objects
called arrElement.
You cannot find Picture in the VB6 class list. However, the fact that there is no error
means that Picture is a valid type. (If you use a random name such as XPIUFS as the
type, VB6 will certainly report that line as an error.) If you do not want to use Picture for
some reasons, you can use Variant.
I have attached my sample code for your reference.
Hope this can help.
Regards
Peter Kwan
|
Re: Bitmap charts in an UDT Array |
Posted by Daniel on May-30-2014 19:09 |
|
Hello Peter,
Yes, first time it was a a spelling mistake and I recognized it immediately but the error
"Can't assign to Array" it is a bit strange to me. I don't know how Picture is a valid type as
long as it is missing from VB6 class list (is it not recognized as class ?).
Beside you say "In each element of the greatArray, it contains another array called
arrElement". You are right, but in this conditions arrElements should be declared as array
(ex. arrElement() As Picture) not as variable (arrElement As Picture). Even you declared the
arrElement as variable I didn't get any error and it worked...
What I do not understand is the fact in my first approach, where I stored charts in byte
arrays (bitmap image) I declared these UDT elements as arrElement() As Byte and the
charts were loaded as array as well, without any error. In a case arrElement worked as
array and in other as variable, or even it is declared as variable is it treated as array ?
I am sorry for this confusion.
A second question is related to your attached example. Referencing Set
greatArray(1).arrElement = c.makePicture() will load in the array a bmp picture or a png
one? And after that, will the clipboard keep the same format further. Thank you.
Regards,
Daniel |
Re: Bitmap charts in an UDT Array |
Posted by Peter Kwan on May-31-2014 01:55 |
|
Hi Daniel,
An image is represented by an array of bytes. For example, a JPG image contains many
bytes, not just one byte. So when you declare a variable to store an image, you either
declare it as a Picture (representing an image), or an array of bytes.
The VB6 intellisense only includes a subset of the classes and interfaces. There are valid
interfaces (such as Picture and IPicture) that are not included in the VB6 list. I think
instead of Picture, you can also use Variant, IPicture, IPictureDisp or StdPicture.
The Picture object is a Microsoft object. It is using an internal unknown format supported
by the operating system. That's why you can copy an image from one application and paste
it into a different application. (The receiving application does not need to support BMP, JPG,
PNG, etc. and it can still receive the image.)
In VB6, all images (BMP, JPG, PNG, etc) must be converted to a Picture object (such as
using the VB6 function LoadPicture) before they can be used by VB6.
Hope this can help.
Regards
Peter Kwan |
|