[vwnc] Images data

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[vwnc] Images data

Syed Mahdi


Hi,

I am trying to store images in Database and I have successully did the storing and retreival of images from the DB, but it only
works for .jpg files and sometimes for Gif. It also works with sound files like wav,mp3 and midi files without any problem. The
problem comes on Tiff, png and most used BMP files as well as avi files.

I tried to only get the image with imagereader and instead of writing it to DB I am writing it back to a folder and the same thing
happened which was happening with retreiving from the DB. It gives me the same file with the same size but the image is unviewable.
So by this test I am positive that storing in the DB is not the problem its just when I get the file from a folder and then write it
back to another folder. The process ends without any exception
For images this is what I am doing

[CODE]
original:= '300px-Lossy.png'.
vwDir := '$(VISUALWORKS)\test' asLogicalFileSpecification.
img := (ImageReader
                fromFile: (vwDir construct: original) asFilename) image.
srcByte := img bits.

vwDir := '$(VISUALWORKS)\test1' asLogicalFileSpecification.
        [newFileStream := (vwDir construct:original ) asFilename
                writeStream binary.


"change upload value asByteArray to the file binary data "
        newFileStream nextPutAll: srcByte]
                ensure: [newFileStream close].
 [/CODE]

If there is something I am missing when writing it back to the file system, I would really appreciate if anyone can point it out to
me. I just hope that my VW isnt messed up somewhere.

Thanks.
Regards,
Syed Mahdi
Software Engineer

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Images data

skrish
original:= 'IMG.png'.
vwDir := 'C:\temp\Photos\IFC_13_sep08' asLogicalFileSpecification.
srcByte := (vwDir construct: original) asFilename readStream binary contents .  " The contents have to be raw binary stream data from the png/bmp/jpg/...any file.."
vwDir := 'C:\temp\Photos\IFC_13_sep08\test' asLogicalFileSpecification.
       [newFileStream := (vwDir construct:original ) asFilename
               writeStream binary.
       newFileStream nextPutAll: srcByte ]
               ensure: [newFileStream close].

I presume the code to obtain the image bits and write it to the file is definetely never going to work.. unless you were to use the specific supported ImageWriter API to do so... The code above is valid for any binary data extending to MSWord/Excel or any such files not just limited to images..

regards,
skrish

On Mon, Sep 15, 2008 at 5:35 PM, Syed Mahdi <[hidden email]> wrote:


Hi,

I am trying to store images in Database and I have successully did the storing and retreival of images from the DB, but it only
works for .jpg files and sometimes for Gif. It also works with sound files like wav,mp3 and midi files without any problem. The
problem comes on Tiff, png and most used BMP files as well as avi files.

I tried to only get the image with imagereader and instead of writing it to DB I am writing it back to a folder and the same thing
happened which was happening with retreiving from the DB. It gives me the same file with the same size but the image is unviewable.
So by this test I am positive that storing in the DB is not the problem its just when I get the file from a folder and then write it
back to another folder. The process ends without any exception
For images this is what I am doing

[CODE]
original:= '300px-Lossy.png'.
vwDir := '$(VISUALWORKS)\test' asLogicalFileSpecification.
img := (ImageReader
               fromFile: (vwDir construct: original) asFilename) image.
srcByte := img bits.

vwDir := '$(VISUALWORKS)\test1' asLogicalFileSpecification.
       [newFileStream := (vwDir construct:original ) asFilename
               writeStream binary.


"change upload value asByteArray to the file binary data "
       newFileStream nextPutAll: srcByte]
               ensure: [newFileStream close].
 [/CODE]

If there is something I am missing when writing it back to the file system, I would really appreciate if anyone can point it out to
me. I just hope that my VW isnt messed up somewhere.

Thanks.
Regards,
Syed Mahdi
Software Engineer

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Images data

Mark Plas
In reply to this post by Syed Mahdi
Hi Syed,

When you write the image back to the file, you only write the 'bits' of the smalltalk Image object. This byteArray only contains the pixel values of the image in some internal format but doesn't contain the meta information needed for .bmp, .tiff, etc files. Some of this information is for instance the width and the height, the number of colors, the amount of compression etc.

You either need something that can create a valid .bmp or .tiff file based on a smalltalk Image instance, or you need to store the .bmp files in your database without first converting them to a smalltalk Image, and only convert them to a smalltalk Image when you need to display it.

Perhaps this helps,
Mark

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Syed Mahdi
Sent: maandag 15 september 2008 14:05
To: [hidden email]
Subject: [vwnc] Images data



Hi,

I am trying to store images in Database and I have successully did the storing and retreival of images from the DB, but it only
works for .jpg files and sometimes for Gif. It also works with sound files like wav,mp3 and midi files without any problem. The
problem comes on Tiff, png and most used BMP files as well as avi files.

I tried to only get the image with imagereader and instead of writing it to DB I am writing it back to a folder and the same thing
happened which was happening with retreiving from the DB. It gives me the same file with the same size but the image is unviewable.
So by this test I am positive that storing in the DB is not the problem its just when I get the file from a folder and then write it
back to another folder. The process ends without any exception
For images this is what I am doing

[CODE]
original:= '300px-Lossy.png'.
vwDir := '$(VISUALWORKS)\test' asLogicalFileSpecification.
img := (ImageReader
                fromFile: (vwDir construct: original) asFilename) image.
srcByte := img bits.

vwDir := '$(VISUALWORKS)\test1' asLogicalFileSpecification.
        [newFileStream := (vwDir construct:original ) asFilename
                writeStream binary.


"change upload value asByteArray to the file binary data "
        newFileStream nextPutAll: srcByte]
                ensure: [newFileStream close].
 [/CODE]

If there is something I am missing when writing it back to the file system, I would really appreciate if anyone can point it out to
me. I just hope that my VW isnt messed up somewhere.

Thanks.
Regards,
Syed Mahdi
Software Engineer

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Images data

Reinout Heeck-2
In reply to this post by Syed Mahdi

> [CODE]
> original:= '300px-Lossy.png'.
> vwDir := '$(VISUALWORKS)\test' asLogicalFileSpecification.
> img := (ImageReader
> fromFile: (vwDir construct: original) asFilename) image.
> srcByte := img bits.
>
> vwDir := '$(VISUALWORKS)\test1' asLogicalFileSpecification.
> [newFileStream := (vwDir construct:original ) asFilename
> writeStream binary.
>
>
> "change upload value asByteArray to the file binary data "
> newFileStream nextPutAll: srcByte]
> ensure: [newFileStream close].
>  [/CODE]
>  
In this code snippet you are writing the bytes of the image (img bits)
to a file.
However these bits are the /internal/ representation of the image, of
course the whole idea of file formats is that this internal
representation needs to be translated to the external file format but
your code does not seem to do that.

To say it in another way:
if you use an ImageReader to read the bytes I would expect to see an
ImageWriter to do that translation in the other direction, but I see none.

Or in yet another way:
you are writing the same bits regardless of whether you want to write
.gif or .jpg -- that cannot be right...



If you rename your variable 'srcByte' to 'internalBytes' your code will
make this bug more obvious ;-)

R
-

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Images data

Maarten Mostert-2
In reply to this post by Syed Mahdi

For as far as I remember the bits of an image go with pallette only. So getting the bits the way you do has no sence.

Either you get the bits directly from the bianary (as I explained you previously) and keep them as such.  Or if you go the image way, you have to decompose the image in a fixed pallette with its associated bits, create some red blue green accessors in fixedpallete to be able to initiate these and keep them together.
I advise you to read the documentation on images it will learn you more details.
 
If I were you however I would stay with the all bianary way for the database and use Cairo to get and display from a tempory file. (Image reader is really slow especially if the pallette of your screen is not the palette of your image.


@+Maarten



> Message du 15/09/08 14:43

> De : "Syed Mahdi"
> A : [hidden email]
> Copie à :
> Objet : [vwnc] Images data
>
>
>
>
> Hi,
>
> I am trying to store images in Database and I have successully did the storing and retreival of images from the DB, but it only
> works for .jpg files and sometimes for Gif. It also works with sound files like wav,mp3 and midi files without any problem. The
> problem comes on Tiff, png and most used BMP files as well as avi files.
>
> I tried to only get the image with imagereader and instead of writing it to DB I am writing it back to a folder and the same thing
> happened which was happening with retreiving from the DB. It gives me the same file with the same size but the image is unviewable.
> So by this test I am positive that storing in the DB is not the problem its just when I get the file from a folder and then write it
> back to another folder. The process ends without any exception
> For images this is what I am doing
>
> [CODE]
> original:= '300px-Lossy.png'.
> vwDir := '$(VISUALWORKS)\test' asLogicalFileSpecification.
> img := (ImageReader
> fromFile: (vwDir construct: original) asFilename) image.
> srcByte := img bits.
>
> vwDir := '$(VISUALWORKS)\test1' asLogicalFileSpecification.
> [newFileStream := (vwDir construct:original ) asFilename
> writeStream binary.
>
>
> "change upload value asByteArray to the file binary data "
> newFileStream nextPutAll: srcByte]
> ensure: [newFileStream close].
> [/CODE]
>
> If there is something I am missing when writing it back to the file system, I would really appreciate if anyone can point it out to
> me. I just hope that my VW isnt messed up somewhere.
>
> Thanks.
> Regards,
> Syed Mahdi
> Software Engineer
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Images data

kobetic
In reply to this post by Syed Mahdi
I believe 'img bits' will give you the "raw" bits of the image as it is represented in memory for displaying, it won't give you the original png bytes. To get that from the image object you would need run the bits through a PNG writer again. So the file that you get in test1 isn't a png file anymore.

If you are just trying to copy file bits then don't read the png file through an ImageReader, just read the binary file stream.

        srcBytes := (vwDir construct: original) asFilename contentsOfEntireBinaryFile

HTH,

Martin

"Syed Mahdi"<[hidden email]> wrote:
> [CODE]
> original:= '300px-Lossy.png'.
> vwDir := '$(VISUALWORKS)\test' asLogicalFileSpecification.
> img := (ImageReader
> fromFile: (vwDir construct: original) asFilename) image.
> srcByte := img bits.


>
> vwDir := '$(VISUALWORKS)\test1' asLogicalFileSpecification.
> [newFileStream := (vwDir construct:original ) asFilename
> writeStream binary.
>
>
> "change upload value asByteArray to the file binary d!
 ata "

> newFileStream nextPutAll: srcByte]
> ensure: [newFileStream close].
>  [/CODE]
>
> If there is something I am missing when writing it back to the file system, I would really appreciate if anyone can point it out to
> me. I just hope that my VW isnt messed up somewhere.
>
> Thanks.
> Regards,
> Syed Mahdi
> Software Engineer
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc