gpt4 book ai didi

c# - 图像在新搜索中没有改变。 C#(asp.net 项目)

转载 作者:太空宇宙 更新时间:2023-11-03 11:38:46 25 4
gpt4 key购买 nike

这使用了 bing 的网络服务。我有一个图像按钮和一组图像按钮。每次单击它时,单个图像都会更改为数组中的下一个图像。问题是如果我单击它并进行新的搜索,图像按钮的数组不会改变。代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using bing_search.net.bing.api;
using System.Collections;




namespace bing_search
{

public partial class _Default : System.Web.UI.Page
{
static ArrayList images = new ArrayList();
static Image[] imagearry;
static ImageButton[] imgButtnsArray;
static int counter = 0;
int fooBarCount = 0;
int firstLoad = 0;
protected void Page_Load(object sender, EventArgs e)
{


}

protected void DoItButton_Click(object sender, EventArgs e)
{
images.Clear();
imagearry = null;
imgButtnsArray = null;

BingService bs = new BingService();
net.bing.api.SearchRequest req = new SearchRequest();
req.AppId = "0B15AB60D625A10059A4A04B68615C5B0D904CA9";
req.Query = SearchBox.Text;
req.Sources = new SourceType[] { SourceType.Image};
req.Market = "en-us";
req.Adult = AdultOption.Off;
req.Image = new ImageRequest();
req.Image.CountSpecified = true;
req.Image.Count = 50;

SearchResponse resp = bs.Search(req);
foreach (ImageResult result in resp.Image.Results)
{
Image im = new Image();
im.ImageUrl = result.MediaUrl;
im.Width = 200;
im.Height = 200;
images.Add(im);
//this.Controls.Add(im);

}
// Image lol = (Image)images[0];



int size = images.Count;
imagearry = new Image[size];
Type typ = typeof(Image);
imagearry = (Image [])images.ToArray(typ);
ImageButton1.ImageUrl = imagearry[0].ImageUrl;
int blaCount = 0;
ArrayList imgButtns = new ArrayList();
foreach (Image ii in images)
{
ImageButton imgb = new ImageButton();
imgb.Width = 200;
imgb.Height = 200;
imgButtns.Add(imgb);
}
size = imgButtns.Count;
imgButtnsArray = (ImageButton[])imgButtns.ToArray(typeof(ImageButton));

foreach (ImageButton iii in imgButtnsArray)
{
imgButtnsArray[fooBarCount].ImageUrl = imagearry[fooBarCount].ImageUrl;
Panel1.Controls.Add(iii);
fooBarCount++;

}
fooBarCount = 0;
counter = 0;

}


protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
counter++;
heightLable.Text = "clicked";
Image tempImage = (Image)imagearry[counter];
ImageButton1.ImageUrl = tempImage.ImageUrl;
foreach (ImageButton iii in imgButtnsArray)
{
imgButtnsArray[fooBarCount].ImageUrl = imagearry[fooBarCount].ImageUrl;
Panel1.Controls.Add(iii);
fooBarCount++;

}
fooBarCount = 0;
counter = 0;
}
}
}

最佳答案

每次点击都会重置两个计数器,因此它总是从同一张图片开始。

fooBarCount = 0;
counter = 0;

它们也不是静态的,所以它们在每次页面加载时都会重置为 0,并显示相同的图像并且不会改变。

如果另一方面是缓存问题,因为我不知道图像文件名是什么,也许这就是这里的问题,那么请尝试类似的方法。

imgButtnsArray[fooBarCount].ImageUrl = imagearry[fooBarCount].ImageUrl + "?rnd=" + RandomNumber.ToString();

关于c# - 图像在新搜索中没有改变。 C#(asp.net 项目),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5392860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com