The jpeg is working.. I use jpegimage.savetofile often and it's fine.. quality at 80, performance left default..
It's something about the stream and its interaction..
Main Topics
Browse All TopicsDelphi 6 Enterprise Edition.
TJPEGImage (from included jpeg unit)
TMemoryStream
jpegimage.assign(bmpcurren
jpegimage.jpegneeded; // yep, I need one
jpegimage.compress; // go go go
jpegimage.savetostream(mem
memorystream.size = 0 -- that sucks
memorystream.position := 0;
memorystream.size = 0 -- still sucks
memorystream.seek(0, 0);
memorystream.size = 0 -- sucks again!
Three sucks and you're out!
Oh, just for the heck of it..
jpegimage.savetofile('c:\t
memorystream.savetofile('c
test1 is fine, test2 is created, proper dimensions, but entirely black. This is intermittent, but seems to happen more often than not.
Is there some other way of getting the jpeg into the stream? I'm pretty sure it's there, but with a size of zero, it's not doing me much good. I really wish the source to the jpeg unit came with delphi.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hmm, i recently have been having a few problems reading and writing to TMemoryStreams, and im not too sure but it could be a bug...
Anyways, the way i ensured the data was ok every time was i used the Move() function
i.e.
Move(source, destination, bytes to copy);
Move(jpegimage, memoryStream.Memory^, sizeof(jpegimage));
Not sure if the parameters are exactly right, you might have to put a '@' at the start of jpegImage or whatever, but take a look at the API..
I found in my sound example that using saveToStream and LoadFromStream commands actually added some garbage bytes at the beggining....
this could be the problem thats plaguing you :)
regards,
L33ty
No, I'm creating the stream.. ;)
And to leety.. I'm not setting it to zero, that was a single =, not a :=. I was just showing that it was equal to zero in the watch window, which causes no end of problems.
The problem is, after the jpegimage.writetostream, the stream doesn't reflect the correct size.. so I don't know how much data was written to it.
Ok, I thought I'd give you some more news.. I'm not sure what could be causing this, but I've been working on this all morning.
I have two routines, one that captures the image off a timer, one that does it immediately with a button click.
The one with the timer is the one having the problem, the buttonclick one works fine..
If I call the button click routine from inside the timer event, it works fine. If I copy the code from the buttonclick into the timer, it goes back to the prior behavior of being the right dimensions but entirely black.
The code in the buttonclick is dead simple :
sDestfile := FileCaptureFrame;
if sDestfile <> '' then
SaveImage(sDestfile);
FileCaptureFrame is a routine that gets the image from the device (bitmap), applies a caption, and just returns me the proper filename. It works fine, no matter where I call it from, at least as far as I can tell.
SaveImage is also a simple routine that in the case of the jpeg, just calls jpegimage.savetofile
I'm starting to suspect some subtle threading issue, even though the application itself isn't threaded, it is making directx/directshow calls to grab the frame from the device.. and maybe the calling context is screwy from the one routine to the other. I can't for the life of me think what that difference might be though.
just a Guess, , ,some "State" of your Direct X capture needs to be upDated, reInitialized, or get a more current reading, when you use the timer, check any variables that are set before the timer event and used in the timer event
or you might try to use the same External function of Image capture in the Button Click and the Timer, or maybe just call the button click procedure in the timer
Slick, I was doing like you suggest, using just one routine to grab the JPEG @ 1FPS. I added code for the internal http server, which was trying to write that jpeg to a stream, and that's what didn't work.
More investigation found that calling those routines from inside an event handler for the Indy TIdHTTPServer component was causing the problem. I have a routine called CaptureAndCaptionFrame, which grabs the image from the device, applies the caption, and stores the bitmap and jpeg.
I added a call to that before the jpegimage.savetostream and everything is working ok. The "deeper" problem I mention in my last posting was just a result of me breaking some code while trying to fix this stream thing.
Everything is working ok now, thanks to everyone for your suggestions, it turns out I think it's just a thread issue with the Indy component somehow coupled with the exposure of certain properties/procedures on the form that has all the directx components. Whatever the case, I'm up and running.
Business Accounts
Answer for Membership
by: Slick812Posted on 2003-05-07 at 21:15:17ID: 8485047
hello asymmetric, maybe you need to give the JPeg some info on HOW TO COMPRESS
am);
TempJpg := TJpegImage.Create;
with TempJpg do
begin
PixelFormat := jf24Bit;
Scale := jsFullSize;
Grayscale := False;
Performance := jpBestQuality;
CompressionQuality := 74;
ProgressiveDisplay := True;
end;
TempJpg.Assign(Bmp1);
JStream := TMemoryStream.Create;
TempJpg.SaveToStream(Jstre
Jsize := Jstream.Size;