Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem loading a picture from an array 2

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
I have a webcam bmp that I can convert nicely to a jpg OK within my app using scraps of software I gleaned from another site.

The jpg picture at this point ends up as a simple byte array that has one element for each byte of the picture. It reduces the original file size by 20 and still gives a very good picture.
Eg if the picture size if 50,000 bytes. ? Ubound(MyArray) = 49999

When saved to a file (using Put) then read back using Loadpicture(Filename) it will show perfectly on an image box.

My problem is how to load the picture array directly into a picturebox without having to save and read it to temporary file as done in one example I found on another site.

Eg. MyPicture.Picture=MyArray obviously does not work

It would appear that Loadpicture is doing something more than just loading the file data into the picture property

How do I convert the array to a picture so I can load it to the imagebox?

I seem to remember an old post that had a suggestion something like this but I cant find it.
 
Hi Ted,
Sorry for unsolicited interference. I didn't see what you are doing in your above code (never got to work with camera API myself).

I just saw function declarations of SendMessage and its variant SendMessageAsLong and wanted to talk about that. Although you are not using SendMessageAsLong in your above code, some other part of program might be using it.

See thread713-1343185 (my second post in particular).
 
Sorry
The SendMessageAsLong has nothing to do with the matter in question.

It is used in another part of the program for a different purpose.

I extracted only the vital parts for simplicity in this question but left this one in accidently
 
Ted, I did not mean to ask WHY did you leave SendMessageAsLong in your above code.

What I meant was that you don't need it (or any other variant of SendMessage) at all, even if you are using it somewhere else. SendMessage function alone can be used in all situations.

Perhaps you didn't see the thread I referenced above.
 
Thanks for that info.

Like many people I use recommended routines from a wide variety of sources and modify or enlarge on them to suit the circumstances- after all, we all do in some way when we uses the examples from Microsoft.

This app uses a number of different routines gleaned from other suggestions and examples and it just happens that the long version was in one of them.

So I wonder why a difference exists?
 
>So I wonder why a difference exists?

Given that you are not entirely certain how this API works (given my long and not entirely fruitful discussion with you about wParam and lParam in the past) I'm not sure it is worth worrying about ...

But basically 'As Any' means exactly that. Any variable type can be passed. VB6 therefore relinquishes any responsibility for type checking (i.e. it doesn't do any at all), meaning that the developer can spectacularly crash their app if they pass a variable type that the function is not expecting. Many code examples, therefore, provide typed declarations of such calls to avoid the problems that may arise with people simply using the example code without understanding what is going on.

SendMessageLong is a typical example of this effort to be type-safe.
 
Thanks.
I understood the reasons for specifying precisions etc and thought I knew why there was a difference.

When I asked "why the difference exists" I was responding to the assertion that SendMessage could be "used in all situations" and the long version was not needed at all

From what you say would appear then that the previous statement is not correct

Any idea yet on the "Unplugged warning" question?
 
> that SendMessage could be "used in all situations"

Shades of the lParam/wParam thread are now coming back to haunt me...

Nothing I said suggests that "SendMessage could be 'used in all situations'" was not correct.

SendMessage can indeed be used in all situations, but the onus is then on the programmer to ensure that the correct type as well as value of parameter is passed.
 
>Any idea yet on the "Unplugged warning" question?

You should be able to use a SysInfo control, and monitor the DeviceRemoveComplete event.
 
>SendMessage could be 'used in all situations'

SendMessage is a classical example where a single parameter can assume different data types (depending upon the individual message being sent). I can recall an earlier discussion on use of Any keyword in SendMessage function in thread222-752892.

But SendMessage is not the only case. There are other functions, in which the argument type changes in different conditions. For instance, LoadIcon and LoadBitmap functions may specify a 32-bit resource identifier as Long, or a named resource as String. Considering this, it is better to specify the resource identifier as Any, instead of Long or String.

Another example is RegQueryValueEx function, in which the type of lpData changes with the type of data being received. It might be a Long, a Byte array or a String depending upon the type of the value being queried (REG_DWORD, REG_BINARY or REG_SZ). Declaring it 'As Any' makes it compatible with all data types.
 
Thanks all
First the good news. WIA works great with XP except I haven't yet found a way of setting the resolution to 640x480 (some posts say you can't anyway)

The bad news is that it doesn't work or even show the viewer in Windows 7

I can't download Virtual XP for Windows 7 because I only have Home Premium

Any suggestions?
Is there another way of writing software to show web pictures in Win7?
 
Also I cant get any response with sysinfo on plugging in a web camera.
Is there something other than the event sub that you have to do first?
 
This thread has gotten a bit long for answering a simple question and it seems to be wandering all over now.

Remember, the purpose of these forums isn't merely to answer your question but also to add to the searchable repository of answers to questions to benefit all.

Deviating all over the board as you so often do may work well for those who try to treat this as an unpaid custom programming service. That isn't how things work here.

Please start a new thread when asking a new question.
 
I'm sorry that this does happen but it is because WIA and Sysinfo are related to answers to my original question and if I don't respond to the success or otherwise of these answers, others think I am ignoring them.

Often the thread wanders because different people suggest alternative methods. I feel obliged to explain why it did or if I had trouble with it.

You may have noted that I have tried to bring some threads back on track in the past.

At least nobody can claim that my threads are not challenging and attract interest!

I am really a 'long retired programmer' and doing it for interest more than financial gain and I do try to help learners if I know an answer to their problem before someone else gets to it first.
 
So now we're talking about image capture and detecting the comings and going of devices?


While I'm a bit of a WIA fan myself, there are things you should be aware of.

From Vista onward WIA was stripped of video-handling to become more of a scanner API. In most cases a webcam won't work with WIA anymore even for still-image capture.

If you think you can run on XP forever I'd wait for those chickens to hatch before placing any bets on it.
WIA 1.0 was introduced in Windows Me and Windows XP and supports scanners, digital cameras and digital video equipment. WIA 2.0 was released with Windows Vista. WIA 2.0 is targeted towards scanners but continues to offer support for legacy WIA 1.0 applications and devices through a WIA 1.0 to WIA 2.0 compatibility layer provided by the WIA service. However, video content support was removed from WIA for Windows Vista. We recommend Windows Portable Devices (WPD) API for digital cameras and digital video equipment in the future. WIA 1.0 as well as STI TWAIN drivers are still supported directly on Windows Vista and Windows 7 alongside native WIA 2.0 device drivers and imaging applications.


Now, WPD is supposed to be the way forward, but there was no VB6-friendly interface to WPD in XP or Vista. This led to some blood-curdling screams, so:
The WPD Application Programming Interface is supported in Windows 7, Windows Vista, and Windows XP operating systems. The WPD Automation Object Model is only supported in Windows 7.
That's right, WPD is useless to you until Windows 7. MS refused to create a back-installable "automation" interface for earlier Windows versions. But even so the "Automation Object Model" is an ugly thing oriented toward JScript and clumsy to use in VB6, VBScript, or much of anything else.

Maybe for portability you're back to using avicap32.dll?
 
Thanks. One thing usually leads to another!

It is a pity that WIA is so neat! But I do really want to use W764 bit. I do a bit of HD video editing and it is so much better.

avicap32.dll works well in Wndows7 64 bit but my big problem with this is the complete computer crashes if you pull out the USB camera plug while it is running.

Then you can't even shut the app down with the taskbar or the computer power button and you eventually get a white screen.

The only way to unfreeze it is to remove the power to the computer plug! (nasty)

I have not been able to find a way to intercept the plug being pulled out before it freezes. That's why I tried Sysinfo but cant get any response from that in W7-64 when I unplug the camera even without the capture running.(probably because I am not using it properly)

That's why I asked if there was anyone who knew how to detect a USB webcam using Sysinfo.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top