|
Right click on the file in the solution explorer and view the properties. There you can control if the file should be copied or not when you compile.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi all, I'm looking for just some ideas, not really specific implementation (although, if you feel like sharing that I'd be thankful).
I have a folder with a very large number of pictures (around 10,000). None of these images are particularly big (about 50 to 100KB each)
My application views these images, 5 at a time, depending on what the user chooses. To be more clear, the images are of various species of birds. For each species there can be 5 to 10 images and, in the application, when the user selects a species, it displays all the images of that species.
I'm using the filenames to identify the species and if a certain species is selected I find the applicable files from the folder by using Directory.GetFiles() matching the relevant file names.
This is the first thing I would like to change. I would imagine that a DB implementation of sorts would be more efficient. I like MySQL and have some experience with it (although not in C# seeing as I'm fairly new to C#). Would MySQL be a reasonable choice or is there anything else I should consider if I want to keep the costs of the final product minimal?
Should I save the images as BLOBs in the DB or should I rather save them to disk and save only the file names to the DB?
Secondly, and this is where I really don't have much of a clue. I would like for the images not to be accessible to the end user, ie. this idea of having a folder on disk with 10,000 images. Is there a reasonable way of putting all of the images in a single file perhaps and have the application extract it from the file as needed? The file would be bg (we're talking of up to 500MB), would that pose significant problems to the operation of my application? What might make this decision more tricky is the fact that I'd like for it to be possible and easy to add and remove images from this file at any time.
Any ideas and suggestions would be appreciated.
|
|
|
|
|
Especially considering that you don't want the files to be accessible by the end user and want to add/remove images at any time I'd go for the database solution.
You could create a thin image access layer and create several implementations that can be switched easily. Something like this:
interface ImageAccess
{
Image[] GetImagesForSpecies(string species);
AddImage(string name);
RemoveImage(string name);
AddSpecies(string name);
RemoveSpecies(string name);
}
On top of this you could create implementations based on file systems, a local database (like SQLite[^]) or a remote database (Oracle, MySQL, PostgreSQL, whatever) where you would have to specify the connection string.
The last solution would make the data changes transparent to the user, the client app wouldn't have to update itself. But the client needs to be connected to the internet.
The filesystem/local-DB solution would require some sort of update mechanism by the client application, but no internet connection would be necessary once all the data is loaded.
I would go for a DB solution (either local or remote) saving the species names and images in relations like this:
Relation species
ID | Name (varchar)
---------
1 | Species1
2 | Species2
3 | Species3
Relation images
ID | Image (BLOB) | Species (FK)
--------------------------------
1 | ... | 1
2 | ... | 1
3 | ... | 1
4 | ... | 2
5 | ... | 2
6 | ... | 3
7 | ... | 3
A nice side effect of using a local database like SQLite is that everything will be stored in a single file, not directly accessible by the user. (Although it would still be possible to extract the images using the SQLite command line tool)
hope this helps,
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Don´t use the load image from path way.
Use a database to store the images, that way only the uses that has acess to the db can see the images.
Download here some articles that show you how to store images in a db.
GoodLuck
nelsonpaixao@yahoo.com.br
|
|
|
|
|
Hi,
I've got a program which runs on computer start-up. Is there some way to detect how the program has been opened?
For example;
If the user opens the program manually (clicking on the program .exe file), it creates a messagebox that says 'foo'.
Whereas if the program is opened by the computer at start-up it outputs a messagebox that says 'bar'.
something like:
if(openedby == user){
MessageBox.Show("foo");
}else{
MessageBox.Show("bar");
}
Just a simple example with, hopefully, a simple answer!
Thanks
|
|
|
|
|
You can send a command-line argument on start up to signal whether a user has ran it or not.
ie: if i run a file like "C:\myfile.exe /startup"
you would check it like this:
bool isUser = false;
string[] args = Environment.GetCommandlineArgs();
if (args[1] == "/startup")
isUser = false;
else
isUser = true;
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Thanks! That sounds brilliant.
I'm setting the application in the startup registry key like this:
rkStartup.SetValue("app name", Application.ExecutablePath.ToString());
can I just change it to this:
rkStartup.SetValue("app name", Application.ExecutablePath.ToString()+" /startup");
My computers old and I'm not particularly keen on restarting it to check as it will take forever
Thanks!
|
|
|
|
|
Okay, I've pretty much got it working (I've booted up my laptop to test it on).
I realised that I should surround the app name in brackets:
rkStartup.SetValue("app name", "\""+Application.ExecutablePath.ToString()+"\""+" /startup");
and it does run on start-up and does what it's supposed to do, but then it crashes It's just a 'program has stopped responding message'.. So I'm looking into that now.
|
|
|
|
|
DragenGimp wrote: and it does run on start-up and does what it's supposed to do, but then it crashes It's just a 'program has stopped responding message'.. So I'm looking into that now.
To debug, go to your project properties and click the debug tab. In the middle you see a box saying "Command line arguments:" add /startup in that box. What that does is, when you start your debugger (f5) it will start your application with that argument. Now you'll be able to see why its crashing.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Thanks.
What happens is it just stops working and it brings up an unhandled error: object was in a zombie state
now I've figured out that it doesn't crash until it reaches this line:
this.WindowState = FormWindowState.Minimized;
now I've got a check on resizing:
void MainFormResize(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized){
this.ShowInTaskbar = false;
notifyIcon1.Visible = true;
}else{
this.ShowInTaskbar = true;
notifyIcon1.Visible = false;
fetch_iniData("data.ini", true);
}
}
For some reason it is the:
this.ShowInTaskbar = false;
That is causing it to crash... I can't see why though.
The strange thing is that it's calling up the same function that is called on a button press, which works fine.. so why it works then and not when the application loads is beyond me
|
|
|
|
|
DragenGimp wrote: now I've figured out that it doesn't crash until it reaches this line:
this.WindowState = FormWindowState.Minimized;
That is real weird. I tried duplicating this issue but i couldn't break it I searched on google and didn't find anything useful. Hopefully, with the resize event everything is working now.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Hi,
I've been absent from my computer for a couple of days, but I seem to have fixed the problem.
I still have no idea why it was crashing, but I simply added this code:
this.ShowInTaskbar = false;
before I called up the minimise function and it seems to stop it from crashing. It's a fix, but I'd still like to know why it was crashing in the first place if anyone figures it out!
Thanks
|
|
|
|
|
Hey everybody
I wrote an application that for some reason has the following problem:
1. In some computers, everything works fine.
2. In some computers (most of them actually ), when visual studio is open (even when no solution is loaded), everything works fine. if we close visual studio the program start consuming 40%-50% CPU! if we run VS again, everything comes down...
Sounds a little bit like a VS Junkie , but I gotta put it in rehab!
Ideas ???
Thanks a lot in advance!
|
|
|
|
|
I need some help regd. dynamic instantiation of classes.
I have a treeveiw, which I populate at runtime by reading from an xml file.
When the user clicks a node, a class should be instantiated and the object is sent to another class.
The issue is, the tree can have any number of nodes and I have to create an object for each click and the class differs depending on the node clicked.(the name of the node is same as the class name that should be instantiated).
I have some basic knowlwdge of Generics.
Can anyone suggest a solution for this...
regards
indey
|
|
|
|
|
If you only have the string of the class and the type is not known at compile time, then you should use reflection and the Activator.CreateInstance[^] method.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You can use reflection, as Greeeg suggested. But, as I use to say, if you need reflection then you are doing something pretty advanced, or something wrong.
Unless the classes can be anything, I would just use a switch to select the class to be created.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
Using VS2008, in a Windows.Form application...
I'm trying to fade an image onto the screen. I first load the image I want use, and then create another image that is nothing more than the same color as the form background. To fade on/off the image, I fade on the actual image, and then fade on the plain background image. Given the following code...
float m_alphaStep = 0.100000000f;
int m_X = 0;
int m_Y = 0;
public void Fade(Bitmap bitmap)
{
float width = (float)m_bitmap.Width;
float height = (float)m_bitmap.Height;
Rectangle destRect = new Rectangle(0, 0, m_bitmap.Width, m_bitmap.Height);
float alpha = 0.000000000f;
try
{
for (alpha = 0.000000000f; alpha < 1.000000000f; alpha += m_alphaStep)
{
m_colorMatrix[3, 3] = alpha;
m_attributes.SetColorMatrix(m_colorMatrix);
m_graphics.DrawImage(bitmap,
destRect,
(float)m_X,
(float)m_Y,
width,
height,
GraphicsUnit.Pixel,
m_attributes);
}
m_colorMatrix[3, 3] = 1.0f;
m_attributes.SetColorMatrix(m_colorMatrix);
m_graphics.DrawImage(bitmap,
destRect,
(float)m_X,
(float)m_Y,
width,
height,
GraphicsUnit.Pixel,
m_attributes);
}
catch (Exception ex)
{
if (ex != null) { }
}
}
public void PaintItem()
{
Fade(m_bitmap);
Thread.Sleep(1000);
Fade(m_offBitmap);
}
Problems:
0) The indicated call to m_graphics.DrawImage() won't compile, despite my using what intellisense claims is a valid overload.
1) The for loop determines the new alpha channel value. The nature of float values causes the alpha value to eventually become some bizarre value (usually by the 7th iteration), which forces me to only do the loop while it's less than 1.0, and then perform the final DrawImage() call after the loop has exited.
2) Performance quite frankly sucks. I can see the image redraw itself from top to bottom. Is there a better (more efficient) way to fade an image on/off the screen?
3) Immediately upon starting the application, I begin displaying the image. If I turn on double-buffering for the form, the form doesn't get displayed until the Fade() routine completes. If I don't turn on double buffering, it works as expected.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: The indicated call to m_graphics.DrawImage() won't compile, despite my using what intellisense claims is a valid overload.
I think that you are reading the intellisense wrong. There is no such overload.
John Simmons / outlaw programmer wrote: The for loop determines the new alpha channel value. The nature of float values causes the alpha value to eventually become some bizarre value
That's not surprising at all. Floating point values are not intended to be exact. You should use an integer value for the loop, and calculate the alpha value from that.
John Simmons / outlaw programmer wrote: Performance quite frankly sucks.
Try to use an overload where you specify the coordinates as integers instead of floats, so that you don't risk getting any scaling when you draw the image.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: There is no such overload.
Well, I coulda sworn I saw that overload. Looking again, it's not there.
Guffa wrote: That's not surprising at all. Floating point values are not intended to be exact. You should use an integer value for the loop, and calculate the alpha value from that.
Well Sparky, I tried that and I still get the wierded out values (and I kinda figured I'd get them - I'm not new at this floating point stuff).
Guffa wrote: ry to use an overload where you specify the coordinates as integers instead of floats, so that you don't risk getting any scaling when you draw the image.
I changed to the appropriate DrawImage( ) function, but no joy. I even tried Invalidate(with image rectangle) , but that doesn't seem to help at all.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: I tried that and I still get the wierded out values (and I kinda figured I'd get them - I'm not new at this floating point stuff).
What kind of "wierded out" values do you get?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
It's really not important since it was bound to occur anyway. But since you asked, when 0.1 is added to 0.6, it comes out as 0.788888888, and then when 0.1 is added to that, it comes out to 8.00000001. Typical floating point stuff.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: 0) The indicated call to m_graphics.DrawImage() won't compile, despite my using what intellisense claims is a valid overload.
It's Point[] , not Point for the second parameter.
So new Point[] { new Point(m_X, m_Y) } should do the trick.
John Simmons / outlaw programmer wrote: 1) The for loop determines the new alpha channel value. The nature of float values causes the alpha value to eventually become some bizarre value (usually by the 7th iteration), which forces me to only do the loop while it's less than 1.0, and then perform the final DrawImage() call after the loop has exited.
As Guffa said, better use a range like 0-255 (or whatever you wish) and calculate the alpha by n/255.
John Simmons / outlaw programmer wrote: 2) Performance quite frankly sucks. I can see the image redraw itself from top to bottom. Is there a better (more efficient) way to fade an image on/off the screen?
Depending on how many iterations you do per second, that's many pixels that need to be modified.
Can't you put the image onto a PictureBox? You could then use the UpdateLayeredWindow interop to change the alpha of the control, which should be faster than your method.
Or just draw the image once on the form and set the Form.Opacity property in a loop.
Both methods will work only on Windows 2000 and upwards, though.
Of course the fastest method would be to use DirectX pixel shaders, but that'd be definitely overkill for your application.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: Can't you put the image onto a PictureBox? You could then use the UpdateLayeredWindow interop to change the alpha of the control, which should be faster than your method.
I guess I could, but you ask that like I knew it was available.
Greeeg wrote: Or just draw the image once on the form and set the Form.Opacity property in a loop.
Can't use Form.Opacity because then the entire window would come and go.
Greeeg wrote: Both methods will work only on Windows 2000 and upwards, though.
That's okay, I'm not concerned with people that are still using Win9x.
Greeeg wrote: Of course the fastest method would be to use DirectX pixel shaders, but that'd be definitely overkill for your application.
I would tend to agree.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi, I get a weird error:
The assembly with display name 'mscorlib.XmlSerializers' failed to load in the 'LoadFrom'
This is what I did
public class ErrorObject
{
[XmlElement("DateTimeError")]
public DateTime DateTimeError { get; set; }
[XmlElement("Message")]
public string Message { get; set; }
[XmlElement("InnerMessage")]
public string InnerMessage { get; set; }
[XmlElement("ErrorPriority")]
public ErrorLevel ErrorPriority { get; set; }
[XmlElement("Dump")]
public object Dump { get; set; }
public ErrorObject(DateTime DateTimeError, string Message, ErrorLevel ErrorPriority)
{
this.DateTimeError = DateTimeError;
this.Message = Message;
this.ErrorPriority = ErrorPriority;
}
}
public enum ErrorLevel { Low, Normal, High, Critical };
and
public void AddMessage(ErrorObject errorObject)
{
List<ErrorObject> errorObjects = new List<ErrorObject>();
errorObjects.Add(errorObject);
XmlSerializer serializer = new XmlSerializer(errorObjects.GetType());
TextWriter textWriter = new StreamWriter(LogFile);
serializer.Serialize(textWriter, errorObjects);
textWriter.Close();
}
No idea what's wrong.
VS2008 is being used.
thx in advance
|
|
|
|
|