I'm facing a problem but since I've never used it before I'm not sure if I'm doing something wrong. I want to store an image to a sd card but the file is 0 bytes length. I get the bitmap from the treo's camera and then I try to save it and then I display the image. Everything works fine and there is no error while storing the image. The bitmap is properly displayed. Here is what I do to store the image (only part of the code, relevant to the pnoJpegLibrary, the complete function is below):
err = pnoJpeg2EncodeCreate(pnoJpegRefNum, &jpegEncode);
if(err == errNone){
pnoJpeg2EncodeToVFS(pnoJpegRefNum, jpegEncode, volRefNum, path);
pnoJpeg2EncodeSetQuality(pnoJpegRefNum, jpegEncode, 50);
pnoJpeg2EncodeProgressive(pnoJpegRefNum, jpegEncode, true);
err = pnoJpeg2Write(pnoJpegRefNum, jpegEncode, bitmapP);
pnoJpeg2EncodeFree(pnoJpegRefNum, &jpegEncode);
}am I doing it right? what am I missing? I hope you can point me to the right direction.
Here is how I get the bitmap, how I get the VFS ref, how I store the image and how I display it. The only problem is with the resulting file (0 bytes).
BitmapType * bitmapP; bitmapP = BmpCreate (previewWidth, previewHeight, previewDepth, 0, &err); UInt16 * bits;
bits = (UInt16 *) BmpGetBits (bitmapP);
for (i = 0; i < previewWidth * previewHeight; i++)
bits[i] = 0x07e0;
err = CameraLibPreview (gLibRefNum, bits, kCameraImageFormatRGB16, previewWidth, previewHeight);
if(!err){
pnoJpeg2EncPtr jpegEncode;
UInt16 volRefNum;
UInt32 volIterator;
Char path[64];
UInt16 pathLength;
FileRef fr;
Err err=0;
Err error=0;
volIterator = vfsIteratorStart;
pathLength = 64;
error = VFSVolumeEnumerate(&volRefNum, &volIterator);
if (error == errNone)
error = VFSGetDefaultDirectory(volRefNum, ".jpg", path, &pathLength);
else
DisplayError("VFS Error", error);
if (error == errNone)
{
if (pathLength > 0 && path[pathLength - 1] == '\0')
pathLength--;
if (pathLength > 0 && path[pathLength - 1] != '/')
path[pathLength++] = '/';
StrNCopy(path + pathLength, "image.jpg", 64 - pathLength);
error = VFSFileOpen(volRefNum, path, vfsModeCreate | vfsModeReadWrite, &fr);
}else
DisplayError("Error reading default directory", error);
if (error == errNone){
err = pnoJpeg2EncodeCreate(pnoJpegRefNum, &jpegEncode);
if(err == errNone){
pnoJpeg2EncodeToVFS(pnoJpegRefNum, jpegEncode, volRefNum, path);
pnoJpeg2EncodeSetQuality(pnoJpegRefNum, jpegEncode, 50);
pnoJpeg2EncodeProgressive(pnoJpegRefNum, jpegEncode, true);
err = pnoJpeg2Write(pnoJpegRefNum, jpegEncode, bitmapP);
pnoJpeg2EncodeFree(pnoJpegRefNum, &jpegEncode);
}
}else
DisplayError("Error openning file", error);
if(err != errNone)
DisplayError("Error saving image", error); if(err == errNone) {
// Now do what you want with the JPEG-Data MemHandleFree(hJpeg);
}WinDrawBitmap (bitmapP, previewLeft, previewTop);
}
I hope you can help me, I can't find any other source of documentation (I switched from Yves Piguet's jpeg library because It's better documented).
Thanks in advance.
Stefan Stolz wrote:
Hi together,
finally i've got the time to complete the pnoJpegLib. Now it's possible to encode 16-Bit Bitmaps into Jpeg-Files. Also, a bug which caused a crash when loading progressive JPEGs is fixed.
Best regards
Stefan Stolz
---
pnoJpegLib: http://www.bin-people.de/pnoJpegLib/
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
