I am working on a small-project similar to popcorn time, but I have faced some issues.
First of all when I call the function which gets all available movies and adds them to FlowLayoutPanel with its cover photos it uses a huge amount of ram like 3 GB! so is there any way to fix this (this == the below code)? (Note that I have checked the function that gets all movies from database alone and it uses only 43MB.)
List<TVShows> T1 = TVShows.GetAll();
TVShowsFlowPanel.Controls.Clear();
for (int i = 0; i < T1.Count; i++)
{
TVShowControl P1 = new TVShowControl(T1[i]);
TVShowsFlowPanel.Controls.Add(P1);
}
second, when I type PictureBox1.picture=http://..... to get the cover picture is there a way to ask if that picture was fully downloaded and showed before I move to the next Movie? and why it takes a long time to get the pic even I am using popcorn time same API with the same internet connection
last, when I add like 80 movies in that flow layout panel, why it's not smooth while scrolling down even the loading process was finished, I mean the pictures show some irritating, random lines until I stay in a specific spot.
Thanks for any help I do really appreciate that!
Related
I am trying to compare two bitmaps to one another. One is premade, and the other one consists of a small image of the main screen being taken and filtered for everything besides full white. I now need a way to compare the amount of white pixels in the live Bitmap to the amount in the premade Bitmap (101 white pixels). A way I know of would be using the Bitmap.Get/SetPixel commands, but they are really slow and as this is used for a kind of time critical application, unfitting.
Especially since I could cut down the filtering process by a factor of 70 by following this guide.
https://www.codeproject.com/articles/617613/fast-pixel-operations-in-net-with-and-without-unsa
I also can't just compare the 2 Bitmaps, as the live one will usually not have the pixels in the same position, but will share the same amount of white pixels.
So yeah. It'd be great if one of you had a time effective solution to this problem.
Edit
Huge oversight on my part. When looking at the filtering method, it becomes apparent that one can just use a counter+=1 every time a pixel is not filtered out.
So I just changed this line of code in the filter function
row[rIndex] = row[bIndex] = row[gIndex] = distance > toleranceSquared ? unmatchingValue : matchingValue;
to this
if(distance > toleranceSquared)
{
row[rIndex] = row[bIndex] = row[gIndex] = unmatchingValue;
}
else
{
row[rIndex] = row[bIndex] = row[gIndex] = matchingValue;
WhitePixelCount += 1;
}
I have around 200 images I need to display one at time in Unity. These need to be held in the application and can't be downloaded from the web.
Right now I have a list set up which takes all of my images and stores. Then, on the hit of a button, I iterate through the list showing each image one at a time. My code looks like this:
public static List <Texture2D> images = new List<Texture2D>();
void Start ()
{
System.Object[] textures = Resources.LoadAll("");
foreach(object o in textures)
{
images.Add(o as Texture2D);
}
}
public static void MoveForward()
{
if(_frameCount < images.Count-1)
{
_frameCount++;
}
else
{
_frameCount = 0;
}
}
However, due to the amount of images I need to store, it's eating my iPads memory. I was wondering if there is a better way in which I could do this where I don't need to load each image at run time, hopefully speeding up the application.
You can resolve this problem in two ways:
1) If you need extra responsibility and no loading time, you can put all your assets in one (or more) spritesheets, then load spritesheet and show specific sprites you need. You can optimize memory usage by compressing this sheet.
2) If you can stand a little loading time (or no noticeable delay, if your images are not big) you can load needed image when you click the button, or keep next image preloaded - then you will have only two images loaded at a time. After that, when you move on and don't need some image right now you can unload it by using Resources.Unload.
Hi guys i just made a small Algorithm to display the fps to my screen.
frames_temp++;
frames_Time += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
if (frames_Time >= 1000)
{
frames = frames_temp;
frames_temp = 0; frames_Time = 0;
}
this code snipped is located in the Update-method. The frame variable stores the actual value drawn to the screen(just posting that code, to make sure there is no fault, eventhough i checked it already).
Now the problem is that i can't turn off the IsFixedTimeStep. I set it to false inside the constructor, initialize and even the update-method but still the programm limits my fps to ~60. I either put in a for() query into my update-method running many million loops without frame-drops to make sure its not my cpu beeing too slow .Another thing i already tried is to use my own timeSpan and the systemtime to get the elapsed time between the calls of Update(), wich gives me kinda the same output. Now it is 99% sure that update only runs 60 times a second.
So why can't i call the Update-Method as often as possible as it should be when IsFixedTimeStep is false
Ty for replies
I believe that you problem is Vertical Syncing, this function of the graphics device is locking the frame rate to your monitor refresh rate. To solve this problem you need to turn off VSync (SynchronizeWithVerticalRetrace) in the GraphicsDeviceManager:
graphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
graphicsDeviceManager.ApplyChanges();
graphicsDeviceManager is your game's GraphicsDeviceManager
If I recall correct fixed timestep = false results in the update being called before the draw method, not calling it as often as possible. Therefore you should check wheter Vsync or something else is limiting your application to 60fps.
I have a few question about charts in .NET in C#, I'm currently working on an app which will display data comming from serial port in real time.
I'm using a simple chart from .NET toolbox with spline series and there are two main feautures which I want to achieve.
The first one - I'd like the comming data points to be displayed on the right part of the chart and I'd like them to move to the left as the new data comes, I don't know how to describe it properly, I hope you can get the main idea since I can't post images yet.
I've achieved this kind of behaviour by reloading all the data points each time I refresh the chart, at first they are all empty and as the data comes I put the bigger and bigger queue of values in the end.
To clarify that the code may be like that:
chartAccelerationX.Series["XSeries"].Points.Clear();
dataPointTable = dataPointQueue.ToArray();
for (int i = 0; i < 1000; i++)
{
DataPoint dataPointX = new DataPoint();
if (1000 - dataPointTable.Length < i)
{
dataPointX.SetValueXY(i + 1, dataPointTable[i - 1000 + dataPointTable.Length].x);
}
else
{
dataPointX.IsEmpty = true;
}
chartAccelerationX.Series["XSeries"].Points.Add(dataPointX);
}
chartAccelerationX.Update();
It works pretty well, but as I said, I'm creating all the 1000 data points each time I update the chart (and I do it every 100ms) so it's probably disastrous in terms of performance (I'll need to have about 6-8 charts in total) and it's limited by the exact number od data points (1000 here).
Isn't there any easier way to achieve something like that with increasing amount of data points dynamically and with the second feature that I wanted to have - an auto matching scroll bar showing for example only 50 records at once?
I've been using a scrollbar as well, but it was just set to show 50 records out of 1000 and I could have scroll through all these empty data points right now.
I can probably make the scrollbar appear after an exact number of data points are on the chart and update it every time the data is added but maybe theres any easier way?
I hope you understood what I was trying to say, I'm still working on my English.
If you can use WPF, there is http://dynamicdatadisplay.codeplex.com/ and for the older WPF version http://dynamicdatadisplay.codeplex.com/wikipage?title=D3v1
which is pretty good, I've used it for some pretty high speed data sampling before
I call a drawing function that I wrote on the data that I need for drawing a graph.
The drawing function works like this: First it creates a text file. It's basically a .dot file, meaning that Graphviz / dot.exe knows how to handle it. The generated file looks something like this:
graph{
resolution=1000;
1[
label =""
pos = "552,552!"
width = 0.002
height = 0.002
fixedsize=true
fontsize = 8
color =red
penwidth = 0.1, color = black, shape = box, width = 0.07, height = 0.07, label = ""
]
74[
label =""
pos = "450,552!"
width = 0.002
height = 0.002
fixedsize=true
fontsize = 8
color =red
shape = point
]
(...)
1 -- 74[penwidth = 0.099, color="red"]
74 -- 40[penwidth = 0.099, color="red"]
40 -- 32[penwidth = 0.099, color="red"]
32 -- 18[penwidth = 0.099, color="red"]
(...)
}
After it generates the file, the function calls the dot.exe process with the following flags:
ProcessStartInfo startInfo = new ProcessStartInfo("dot.exe");
startInfo.Arguments = "-Kneato -Goverlap=prism -Tpng " + fileName + ".txt -o " + fileName + ".png";
I've tried using different flags, image formats etc., but none of that solves my problem.
My application basically consists of an interface with a few buttons and two PictureBoxes. Clicking on one of the buttons causes the "important part of the program" to execute.
The "important part" takes some time to execute, so I used a BackgroundWorker for that. What happens over there (in the backgroundWorker1_DoWork function) is:
Some things get calculated and my drawing function gets called twice on the resulting data. It creates two images and "puts them" into the PictureBoxes.
And it works just fine for most data, but for some data it doesn't. On some of the data, no pictures get shown in the PictureBoxes. When I check the folder where the text files and the images should have been created, I see that only the text file and the resulting picture which should go into the first PictureBox are created... But not even they are shown. My conclusion is that something makes the whole BackgroundWorker process stop, probably some kind of an error in the dot.exe process.
Now, every time the process gets called, a console appears for a glimpse of a second. Some useful data might be displayed over there, but I don't know how to read it.
There's a previous and slightly different version of my application, which doesn't work on the same data that the current version fails to work on.
In the old version, however, I'm able to read the console output (probably because the whole program crashes), and it says something along the lines of:
Graph is too large for cairo renderer bitmaps.
Scaling by 0.4 to fit dot: failure to create cairo surface: out of memory.
I get this error mostly for larger graphs, but not only for larger graphs. Some larger graphs work just fine, and some smaller ones don't. And none of them are particulary large anyway: The largest are approximately 80 nodes large. I thought it might have something to do with resolution or something like that, but whatever parameter I change, the thing still doesn't work.
Does anyone have an idea on what I should try? Do you need any extra information about my problem?
Edit: Also, changing the size using the -G attribute doesn't help. In fact, whatever I do I always get the exact same error, meaning that the scaling factor mentioned in the error doesn't change.
Turns out my problem was nothing Graphviz or even graph specific - I was testing my (metaheuristic) algorithm on the test examples I found online. When reading the optimal solution files line by line and splitting them into words, "" would sometimes get recognized as a word.