×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    31

    Loading Image from Memory instead of file..

    Hi All,

    Can someone help me with the following problem.

    I have a datastream loaded into a variable (s in this example) which contains all the jpeg file data.

    Currently the only way I can load the image is to save the datastream to a temp file, then load it, then delete the temp file.

    This isn't too complex but feels like it is bad coding.

    Is there a way in python to load an image directly from a variable.

    current bloaty code:
    Code:
    f=open('c:\\temp.jpg','wb')
    f.write(s)
    f.close()
    img=Image.open('c:\\temp.jpg')
    os.remove('c:\\temp.jpg')
    Thanks
    Jamie

  2. #2
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    65

    Re: Loading Image from Memory instead of file..

    You can try to save the file in D:\, instead of C:\.

  3. #3
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    65

    Re: Loading Image from Memory instead of file..

    I've just tried e very very very very simple benchmark!
    Code:
    >>> import time
    >>> def ben(d, s):
    ...     f = open(d+u'file.txt', 'w+')
    ...     t = time.time()
    ...     f.write('0'*s*1000000)
    ...     f.close()
    ...     print '%f MB/s' % (float(s)/(time.time()-t))
    ...
    >>> ben('D:\\', 10)
    2.500000 MB/s
    >>> ben('C:\\', 10)
    0.263158 MB/s
    >>> ben('E:\\', 10)
    0.153846 MB/s
    >>>
    As you can see, D:\ is about 10 times faster then C:\

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    31

    Re: Loading Image from Memory instead of file..

    Hi Ale152,

    Thanks for that, its interesting to know. I'll use D from now on.

    But I was still really hoping to bypass writing the file at all. I'm sure Python has the ability to have a faux file using StringIO but im struggling to get it to work.

    Thanks for your efforts though!

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    3

    Re: Loading Image from Memory instead of file..

    Hi All,

    I also hope to find a way to bypass saving file. In fact I'm grabbing viewfinder frames and saving them to SD Card, then opening them to send them to socket. The important part is that when I save image it get encoded to JPG ( I really need this ) and then stream JPG data.

    The question is can I get JPG data out of viewfinder image in PyS60?

Similar Threads

  1. desperately needs help on how to save an image in the mobile device memory
    By daregazi in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2008-06-23, 12:37
  2. Replies: 2
    Last Post: 2008-03-20, 02:07
  3. Contacts fields order??
    By timatima in forum Symbian
    Replies: 1
    Last Post: 2007-06-08, 13:51
  4. Replies: 0
    Last Post: 2005-03-08, 08:14

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×