Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I try "pictureBox1.Image = img;" but it dosent work
Cannot implicitly convert type 'System.Windows.Controls.Image' to 'System.Drawing.Image'


This (Image img = new Image) = System.Windows.Controls.Image

C#
private void button4_Click(object sender, EventArgs e){
     GimageSearchClient client = new GimageSearchClient("http://www.google.com");
            IList<IImageResult> results;
            IAsyncResult result = client.BeginSearch(
                textBox1.Text.Trim(),  //param1
                10, //param2
                ((arResult) => //param3
                {
                    results = client.EndSearch(arResult);
                    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Send,
                        (Action<IList<IImageResult>>)(async (data) =>
                         {
                             Random r = new Random();
                             Image img = new Image
                             {
                                 Source = await DownloadImage(results[r.Next(results.Count)].TbImage.Url),
                                 Stretch = Stretch.UniformToFill,
                                 StretchDirection = StretchDirection.DownOnly,
                             };
                                                          
                             //////// img add to Picturebox HOW ? 

                         }), null);
                }),
                null //param4 
                );
        }
Posted

1 solution

They are not immediately compatible, meaning they cannot be cast from one to the other. This Link[^] has some example code on how to convert from one to the other.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900