Hi All.
I have a listbox with file names in it, and I want to read in a line, and then put the image into a Canvas, and I can’t figure out the syntax.
Any help?
Regards
Hi All.
I have a listbox with file names in it, and I want to read in a line, and then put the image into a Canvas, and I can’t figure out the syntax.
Any help?
Regards
That’s a very vague description of what you’re trying to do. And it requires a lot more than just a few lines of code. Here are a few resources that will help you.
Here is a Project to get you started with your idea:
ImageBrowser.zip (6.2 KB)
And a last one, because i still had some time… ![]()
ImageBrowser.zip (7.2 KB)
@Emile_Schwarz… It’s a proof of concept. I could not care less about mentioned flaws… ![]()
@Michael_Cebasek has been a valuable member for many years…
It took me four to five hours to respond. This is a forum, not a WhatsApp chat… ![]()
Since I didn’t think it was necessary, I let Claude.ai make the changes.
ImageBrowser.zip (6.9 KB)
Hi Emile.
I respond as soon as I get a chance. And am always appreciative of any help I get. Sometimes, I just need a new way of looking at things so that I can get what I am missing.
I don’t mean any disrespect by not answering within 2 minutes.
Regards
thanks for the response, Sascha.
I did an initial test of my “logic” and code the same way.
But when I go to step through a folder, and put an image in my Canvas, as a background, I get nothing
Here is my code.
It doesn’t error, but it doesn’t work. The Canvas1 never fills in:
var comparisonPicture1 as Picture
var comparisonPicture2 as Picture
(some make pretty code here)
For filesInTheFolderCount = 0 To howManyItemsAreInThisFolder - 1
comparisonPicture1 = Picture.Open(theNativePathChosenForVideoFolder)Canvas1.Backdrop = comparisonPicture1
Next filesInTheFolderCount And since writing this, like 2 minutes ago, I found that needed to call the folder items with .Child. Stay tuned, and thanks everyone for your help so far!
I assume you don’t do it, but i’ll mention it anyways. Remember to not use the Backdrop Property in the Paint Event of a Canvas. The Xojo Documentation says:
“You should not assign a new picture to the backdrop of the control when being inside the Paint event of that control. This can lead into problems like the backdrop not being painted.”
Do you compare Pictures by doing something like a comparisonPicture1 <> comparisonPicture2 ? If you do, i’d like to recommend to create a MD5-Hash while reading a Folder (and creating the Thumbnails) and later just compare the MD5-Hashes. Should be much faster.
It’s hard to tell whats causing issues here. Still to less information.
For example:
Start by testing the following: Put a Line Canvas1.Refresh after the Line Canvas1.Backdrop = comparisonPicture1 and see if the Picture will be displayed then.
Hi Sascha.
Thanks for the information.
I will try and answer questions to the best of my ability.
First: This code works.
var comparisonPicture1 as Picture var comparisonPicture2 as Picture
// (some make pretty code here)
For filesInTheFolderCount = 0 To howManyItemsAreInThisFolder - 1 comparisonPicture1 = Picture.Open(theNativePathChosenForVideoFolder) Canvas1.Backdrop = comparisonPicture1
Next
I realize I will have to scale the image, I was just trying to get the image into my cavas.
What I am attempting to do is look for duplicate images in a folder so I can ditch duplicates. I know there are other programs out there, but they don’t meet my desires i.e. (name and image compare the way I want them. Hence the program)
What I will be doing is checking for duplicates first by similar name, then by actually image.
I have a method that will compare two images if I open them manually and give me what I want.
So stay tuned.
And once again to everyone who responded thank you for the knowledge and assistance.
Regards
Wouldn’t your routine loop through the folder and display all the images as fast as possible in Canvas1? Is this for a nice effect, or does it have a specific purpose?
How about:
Var comparisonPictures() As Picture
Var comparisonPicture2 As Picture
// (some make pretty code here)
// Make sure we have a valid source folder
If PictureFolder = Nil Or Not PictureFolder.Exists Or Not PictureFolder.IsReadable Then Return
// Wouldn't the following routine loop through the folder and display the images one by one in Canvas1?
// Is this for a nice effect, or does it have a specific purpose? :-)
// Get count of files
howManyItemsAreInThisFolder = PictureFolder.Count - 1
// Iterate through all files
For filesInTheFolderCount = 0 To howManyItemsAreInThisFolder
// Make sure the file is readable and then...
// Do a ProportionalScale and add the Picture to the Array
comparisonPictures.Add ProportionalScale( Picture.Open( theNativePathChosenForVideoFolder ), Canvas1.Width, Canvas1.Height )
Next
// Make sure the Array isn't empty
If comparisonPictures.Count = 0 Then Return
// Display the 1st Picture in Canvas1
Canvas1.Backdrop = comparisonPictures(0)
Public Function ProportionalScale(Pic as Picture, Width as integer, Height as Integer) As Picture
// calculate the scale factor
dim factor as Double = min( Height / Pic.Height, Width / Pic.Width )
// Calculate new size
dim w as integer = Pic.Width * factor
dim h as integer = Pic.Height * factor
// create new picture
dim NewPic as new Picture( w, h, 32 )
// draw picture in the new size
NewPic.Graphics.DrawPicture( Pic, 0, 0, w, h, 0, 0, Pic.Width, Pic.Height )
// return scaled image
Return NewPic
End Function
Thanks for this Sascha.
I had something… similar. Not as graceful as yours, but it worked (after hours of bad words.)
I will study what you supplied to be a better grasp of what you have here.
Thanks to everyone for their help with my issue.
Regards