I've been working on this all afternoon and it is driving me slowly more insane than I already am!
My program is set up to import a load of JPEG files that you drag onto it. This all works fine. I select an album, drag the images from a Windows Explorer window into the mane panel and after a period of time they all appear as expected. If there are a lot of images or they are very large, then it takes quite some time and during this time I can't get any indication of progress.
I've added a ProgressBar and set up a timer to check the state of a progress variable and update the bar. I have tried to offload the hard work by using CallSubDelayed. This seems to improve responsiveness but the timer only fires right at the end. I only know this because all the log of the progress variable shows a progress of 1 and appears all at the same time, once for every call to the sub.
These two subs loop through the dropped images
and this one in the Graphics Module does the sizing. This will be the one that takes a long time.
I've attached the project and any help would save my sanity.
I'm using JRLDialogs8 and jDragAndDrop so you may need these.
David
My program is set up to import a load of JPEG files that you drag onto it. This all works fine. I select an album, drag the images from a Windows Explorer window into the mane panel and after a period of time they all appear as expected. If there are a lot of images or they are very large, then it takes quite some time and during this time I can't get any indication of progress.
I've added a ProgressBar and set up a timer to check the state of a progress variable and update the bar. I have tried to offload the hard work by using CallSubDelayed. This seems to improve responsiveness but the timer only fires right at the end. I only know this because all the log of the progress variable shows a progress of 1 and appears all at the same time, once for every call to the sub.
These two subs loop through the dropped images
B4X:
Sub ScrlMainView_DragDropped(e As DragEvent)
If CurrentAlbum=-1 Then Return
Dim Files() As String
Dim FileList As String=e.GetDataObjectForId("text/uri-list")
FileList=FileList.Replace("file:/","").Replace("/","\")
Files=Regex.Split("\r\n",FileList)
If Files.Length=0 Then Return
ProgWorking.Progress=0
TimerMain.Enabled=True
Dim gap As Double = 1/Files.Length
Dim count As Int=0
For Each source As String In Files
If source.Contains(".jpg")=True Then
count=count+1
CallSubDelayed3(Me,"InsertPicture",source,count*gap)
End If
Next
End Sub
Sub InsertPicture(Source As String, Position As Double)
Dim imgname As String=File.GetName(Source)
imgname=imgname.Replace(".jpg","")
Dim imgwork As Image=Graphics.ResizeImage(Source,120)
Dim imgaspect As Int=0
If imgwork.Width>imgwork.Height Then imgaspect=1
Dim blob() As Byte
blob=Graphics.CreateSQLiteBlob(imgwork)
SQLMain.ExecNonQuery2("INSERT INTO pictures (_album,source,title,thumb,aspect) VALUES (?,?,?,?,?)",Array As Object(CurrentAlbum,Source,imgname,blob,imgaspect))
ProCount=Position
FillPhotoPanel
End Sub
and this one in the Graphics Module does the sizing. This will be the one that takes a long time.
B4X:
Public Sub ResizeImage(Source As String, Size As Int) As Image
Dim temp As Image
temp.Initialize(File.GetFileParent(Source),File.GetName(Source))
Dim wid As Int=temp.Width
Dim hid As Int=temp.Height
If wid>hid Then
Dim swid As Int=Size
Dim shid As Int=(Size/wid)*hid
Else
Dim shid As Int=Size
Dim swid As Int=(Size/hid)*wid
End If
Dim temp2 As Image
temp2.InitializeSample(File.GetFileParent(Source),File.GetName(Source),swid,shid)
Return temp2
I've attached the project and any help would save my sanity.
I'm using JRLDialogs8 and jDragAndDrop so you may need these.
David