Flush Imagesource

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Flush Imagesource

Post by Simon Knight » Fri Jun 01, 2018 5:35 pm

I have a table that lists the jpeg files in a folder. Some of these jpegs are thumbnails set to 100 pixels on the longest edge. I set the imagesource of a character in each row of the table and the thumbnails are displayed in the table. So far so good.

Next I update the thumbnails in the folder making them 150 pixels on the longest edge. I then re-run the handler that sets the imagesource for a character in each row. I expected the images would resize but they stay the same as previously i.e. 100 pixels on the longest edge.

Code: Select all

 put field "ImageList" of me into tList
   set itemdel to tab
   put 0 into tIndex
   repeat for each line tLine in tlist
      add 1 to tIndex
      put item 5 of tLine  & "/Tiny_" & item 2 of tline into tFileSpec
      set the imagesource of char 1 of line tIndex of field "ImageList" of me to "binfile:" & tFileSpec
   end repeat
I have tried setting the imagesource to empty before setting it back to the image URL but Livecode remembers the old image. Any ideas on how to flush the imagesource buffer?
best wishes
Skids

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Flush Imagesource

Post by jmburnod » Fri Jun 01, 2018 5:52 pm

Hi Simon,
I have tried setting the imagesource to empty before setting it back to the image URL
What happens if you set the imagesource to url of a file "MyBlankImg.jpg" instead empty ?
Jean-Marc
https://alternatic.ch

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Flush Imagesource

Post by Simon Knight » Sat Jun 02, 2018 7:13 am

Hi Jean-Marc,

It works!

Thanks for the idea. I would have thought that it would raise an error but it does indeed clear the buffer.
best wishes
Skids

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Flush Imagesource

Post by jmburnod » Sun Jun 03, 2018 9:48 pm

HI Simon,
I'm curious to know why you use imagesource to display images instead a group of images with referenced file.
Best regards
Jean-Marc
https://alternatic.ch

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Flush Imagesource

Post by Simon Knight » Mon Jun 04, 2018 9:20 am

Hi Jean-Marc,

Thats a good question. The short answer is because I don't know any better! The long answer follows.

I have used Runrev/Livecode on and off for a number of years, shortly after I started the DataGrid was introduced and I decided that in order to be a "real" LC programmer that I should use datagrids. Now while I have had some success with them I have almost had problems during development typically with want I have called "silent failures". However, despite these problems I continued to use datagrids. Its worth saying that most of may applications have been utilitarian and have just used stock controls.

Moving forward to my present project. This project started out with the aim of outputting a CSV file that describes a folder of images. Initially I displayed a list of images in a datagrid and the user was allowed to select a single a line to add a title and a caption while the selected image was displayed in a graphic control. I used a second datagrid to display a simple list of text. At this point I posted details on this board details of my efforts with this datagrid (see-Using a DataGrid as a simple list control). Craig kindly replied and basically said "why not just use a simple list control"?

This made me realise that I did not really know what I could be achieve with "simple" field controls. So I decided to find out. I found examples of good looking list controls such as Bernd's modtablefield and the work of Scott Rossi and I tried to understand how they worked. I rewrote my application to use a table field to list the text and I showed it to a beta tester, he asked for thumbnails to be added to the list and that it should be possible to drag them into the required order.

Fortunately Scott published an example of a good looking table that implemented drag and drop by making a screen shot of the line to be moved. I used this code and applied it to my own table and much to my surprise I got it working. Adding images means that the rows are odd heights and that the inbuilt cell editing does not work nicely. So I used a second field which is resized and overlaid over the target field for data entry. I guess that this is all old hat for many readers but its all new to me.

At this time I had also found a video made of Scott talking about user interfaces. One of the examples he presented was of a grid of thumbnails on a page. The application allowed the user to swipe between pages. It looks really good but I have no detailed idea how it is implemented.

I decided that I complete my list based application and then have a go at a grids of images on cards. At present my list of images allows reordering using drag and drop and data editing using a second field placed above the cell in the main table. I'm quite pleased with it although I'm sure my code could be improved. Its taken me a week of experimentation and I have not had any odd unexplained LC crashes or silent failures. I find it quite empowering that all the code is simple to locate and edit and also perhaps more importantly the message path is simpler for both me and LC.

So my programming journey continues.
best wishes
Skids

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Flush Imagesource

Post by jmburnod » Tue Jun 05, 2018 11:17 am

Hi Simon,
Thanks for explanations.

I told about images because referenced images can be resized as you want.
I dont know how many images you have to display in the same time but I think you may make your app faster using images instead imagesource.

Of course you have to manage proportional resize but scripts exist for this.
Do you can use .png files instead .jpg because we can to know the width and height of a .png file without displaying the image.

You can have a group for each image: one white grc as background, one referenced image and one fld. You may decide how distribute space for image and fld and adjust textsize of the field according with the lenght of his content.
Best
Jean-Marc
https://alternatic.ch

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Flush Imagesource

Post by Simon Knight » Tue Jun 05, 2018 11:31 am

Hi Jean-Marc,
Thanks for sharing your ideas. I intend to write a new app once my list based one is working well enough to use. At present I am using jpegs but there is no reason not to use png files and I did not know a being able to get the size from the file.

Ben Beaumont created a demo stack at RunRev (09 I think) that displayed twenty or so thumbnail images on white backgrounds (last card of this stack based presentation https://www.dropbox.com/s/gvrbcysrpln7v ... a.rev?dl=0 ).

I was planning to use a group to display the image plus two fields for text entry and some custom values. once the card of image groups has been created I want to be able to move them into a display order.

But this is all in a couple of days time .
best wishes
Simon
best wishes
Skids

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Flush Imagesource

Post by jmburnod » Thu Jun 07, 2018 5:55 pm

Hi Simon,
I did not know a being able to get the size from the file
You may get the script here
http://forums.livecode.com/viewtopic.ph ... 386#p58690
I want to be able to move them into a display order
I remember something of a Craig's sentence about changing order of objects.
Often that is simpler to have a script which is able to refresh all objects than change locations.
Good luck for next step(s)
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Flush Imagesource

Post by dunbarx » Thu Jun 07, 2018 7:38 pm


Post Reply

Return to “Talking LiveCode”