内存不足的 Coverflow [英] Coverflow with Out of Memory

查看:17
本文介绍了内存不足的 Coverflow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Windows 8 Phone 应用程序.

i am working on Windows 8 Phone Application.

我有一个问题,我正在一张一张地在图像顶部加载带有文本的图像.它被称为覆盖流功能.

I have issue where i am loading image with text on top of the images one by one.Its called coverflow feature.

我收到内存不足异常

for (int j = 0; j < items.Count; j++)
            {
                for (int i = 0; i < items.Collection.Count; i++)
                {
                    Myobj obj = items[j].Collection[i];
                    if (obj.correct == 1)
                    {
                        coverflow.Add(new CoverFlow(items[j].Text, answer.TextTwo));
                    }
                }
            }

            CarouselList.ItemsSource = coverflow;

数据模板:

<DataTemplate x:Key="DataTemplate1">
            <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Border Grid.Row="0" Height="400" Width="400" CornerRadius="30,30,30,30">
                    <Border.Background>
                        <ImageBrush ImageSource="Images/sample.png" />
                    </Border.Background>
                </Border>
                <Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top">
                    <TextBlock HorizontalAlignment="Center" 
                               VerticalAlignment="Center"
                               Margin="5,20,5,5"
                               Foreground="#000000"
                               Text="{Binding Title}"/>
                </Grid>
                <Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <TextBlock HorizontalAlignment="Center" 
                               VerticalAlignment="Center"
                               Margin="5,5,5,20"
                               Foreground="#000000"
                               Text="{Binding SubTitle}"/>
                </Grid>
            </Grid>
        </DataTemplate>

这里有大约 300 多个项目一个接一个地显示:

Here the there are around 300+ items that displays one after the other:

像这样:

它根本不起作用我试图将宽度和高度从 400 减少到 200 它有效,但我希望图像大小为 400,以便它看起来不错.

Its not working at all i tried to reduce the widht and height from 400 to 200 it works but i want the image size to 400 so that it looks good.

即使我的图像是 400*400,我如何避免这种内存不足

how can i avoid this Out Of Memory even if my images are 400*400

推荐答案

这真的是我脑中浮现的问题.好久没处理了.

This is going to be really from the top of my head. Haven't dealt with this in a while.

1.给自己写一个函数,它会返回一堆项目

1.Write yourself a function which will return you a bunch of items

public List<Item> GetFirstItems()
{
    return items.Collection.Take(50);
}

public Item GetOtherItems(int skip)
{ 
     return items.Collection.Skip(skip).Take(25)
}

2.为您的控件连接SelectionChangedEvent

//keep this somewhere so you know where you are in the list
var currentBatch = 0;

private void SelectionChanged(sender object, ChangedEventArgs e)
{
     var position = e.CurrentItemIndex % 25;

     if(position > currentBatch)
     {
          currentBatch = position;
          var newItems = GetOtherItems(currentBatch * 25);

          //take the global list of items and modify it;
          //because we are moving right we only need the last 25 so we
          //can skip the first 25
          coverflow= coverflow.Skip(25);

          //add your new items
          coverflow.AddRange(newItems);
          CarouselList.ItemsSource = coverflow; // you will have to clear the source first
     }
     else if(position < currentBatch)
     {
          currentBatch = position;
          var newItems = GetOtherItems(currentBatch * 25);

          //take the global list of items and modify it;
          //because we are moving left we only need the first 25 so we
          //can take the first 25
          coverflow= coverflow.Take(25);

          //add your new items
          newItems.AddRange(coverflow);
          coverflow = newItems;
          CarouselList.ItemsSource = coverflow; // you will have to clear the source first
     }
}

您还需要注意的另一件事是记住哪个是当前项目并将其重新设置为当前项目.

One more thing you will have to take care of is memorizing which was the current item and setting it again to be the current item.

这一切都是从我的头顶写的,我不知道它是否适用于您的控制,但我希望它至少能对您有所帮助:)

This is all written from the top of my head and I have no idea if it work with your control but I hope it will at least help you a bit :)

这篇关于内存不足的 Coverflow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆