|
Thank you, it works.
|
|
|
|
|
Hello everyone,
I use the following code to place an image "temp.jpeg" into an array and then write the array into a remote database.
int FileSize;<br />
byte[] ImageArray;<br />
FileStream fs;<br />
int iBytesRead;<br />
<br />
OpenFileName = "temp.jpeg";<br />
<br />
fs = new FileStream(OpenFileName, FileMode.Open, FileAccess.Read, FileShare.Read);<br />
FileSize = Convert.ToInt32(fs.Length);<br />
<br />
ImageArray = new byte[FileSize];<br />
iBytesRead = fs.Read(ImageArray, 0, FileSize);<br />
fs.Close();
I was wonder what I should do if the image is not a file such as "temp.jpeg" and it is the image displayed in a Button?
Can someone be kind enough to help me out on this one?
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
You can save the image displayed in a Button to temporary file, and after that read from this file. Or you can save this image to stream, and then read it's data to array.
My english is not so good. Please, correct my errors.
Best regards, Alexey.
|
|
|
|
|
Does anyone know if it is at all possible to take an ImageList of large icons, resize them, and dump the smaller images into another ImageList? I am trying to do this dynamically since I will not have any smaller versions of the icons available to me.
|
|
|
|
|
I am pretty sure I have some sort of syntax problem here but I can't get my head around it, dont see anything wrong.
I have made a class called cRoom, I create several room objects from this and shove them in an ArrayList.
class cRoom
{
//variables left out for better viewing
public cRoom(//insert loads of strings and ints here)
{
}
// All the public get/sets go here, again left out for better viewing.
}
//at some point in my Main() program ill call a method called North
//rActive is a cRoom object, arrRoomList is an array of cRooms
rActive = North(rActive,arrRoomList)
// The method for North
public static cRoom North(cRoom activeRoom, ArrayList roomList)
{
if (activeRoom.NORTH != 0)
{
foreach (cRoom room in roomList)
{
if (room.RID == activeRoom.NORTH)
{
return room;
}
}
}
else
{
Console.WriteLine("I can't go that way.");
return activeRoom;
}
}
Anyway when the code is compiled I get two errors.
Inconsistent accesibility: return type ....cRoom is less accessible than method.....North
Inconsistent accesibility: parameter type...cRoom is less accessible than method....North
Thanks in advance. =)
|
|
|
|
|
The cRoom class is private and the North method is public. That means that the method is available outside of the surrounding class, but it's unusable as it's impossible to create the cRoom object that is needed for calling it.
Just make the method private also.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanks! Worked a charm.
Its decided to throw another one at me now.
'Adventure.Program.North(Adventure.Program.cRoom, System.Collections.ArrayList)': not all code paths return a value
which I am guessing has something to do with the ArrayList
im only returning the cRoom object
|
|
|
|
|
Not all code paths return a value...
What code paths is it refering to?
code paths in a class or in the method?
|
|
|
|
|
the variables in my class cRoom are private
but they all have public get/set returns
I dont see what I am missing
|
|
|
|
|
eh woops I think I just figured it out
edit:
eh nope, still the same thing
each room has a number associated to their north south east and west exits
if its 0 there is no exit that direction
otherwise its 101 or 102 etc.
so if activeRoom.NORTH != 0 then its going to == 102 or another number
then I take that number and shove it into int RID
then I search each cRoom in the arraylist for that value
and if it finds it then it takes the rooms value and drops it into the activeRoom and its returned
|
|
|
|
|
Ok I solved the problem...
For some reason it didnt like the fact that I had the return activeRoom; in the follow position
foreach (cRoom room in roomList)
{
if (room.RID == RID)
{
activeRoom = room;
return activeRoom;
}
}
So I moved it here
foreach (cRoom room in roomList)
{
if (room.RID == RID)
{
activeRoom = room;
}
}
return activeRoom;
and it worked fine
I guess I cant have a return value in a foreach loop
Thanks for your help. =)
|
|
|
|
|
jblouir wrote: I guess I cant have a return value in a foreach loop
You can, although it's good form to only have one return, at the end of a method.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
jblouir wrote: im only returning the cRoom object
Not always, that's what the error message is saying.
Look at the logic in the method. If activeRoom.NORTH is non-zero but not found in the list, the method doesn't return anything.
---
single minded; short sighted; long gone;
|
|
|
|
|
If you declare a method that returns a value, you must make sure that all places where you may exit the function will return a value of that type. Example:
public int MyFunc()
{
if (errorcondition)
{
return 2;
}
else
{
...
}
return 0;
}
}
|
|
|
|
|
I am trying to use the same class to populate the second list in my second class, but the list will have the last set of values. The only way that it work if I instantiate multiple classes, please help, why I can not use only instantiating my classes once . Here are the codes
<b><pre>First file</pre></b>
<code>
using System;
using System.Collections.Generic;
using System.Text;
namespace xpop
{
class Program
{
static void Main(string[] args)
{
_xobj xobj = new _xobj();
popxmlobj(xobj);
}
// Does work but have to instatiate the calss object twice need to re- use the calss object
static void popxmlobj1(_xobj xobj)
{
_AllValue aValue1 = new _AllValue();
aValue1.valueName = "VAL1Name";
aValue1.Values.Add("Val1");
xobj.fieldName = "FieldName1";
xobj.fieldValues.Add(aValue1);
_AllValue aValue2 = new _AllValue();
aValue2.valueName = "VAL2Name";
aValue2.Values.Add("Val2");
xobj.fieldValues.Add(aValue2);
}
// Works if I use this method
static void popxmlobj(_xobj xobj)
{
for (int i = 0; i < 2; i++)
{
if (i == 0)
{
_AllValue aValue1 = new _AllValue();
aValue1.valueName = "VAL1Name";
aValue1.Values.Add("Val1");
xobj.fieldName = "FieldName1";
xobj.fieldValues.Add(aValue1);
}
if (i == 1)
{
_AllValue aValue1 = new _AllValue();
aValue1.valueName = "VAL2Name";
aValue1.Values.Add("Val2");
xobj.fieldValues.Add(aValue1);
}
}
}
}
}
</code>
<b>pre>Second file</pre></b>
<code>
using System;
using System.Collections.Generic;
using System.Text;
namespace xpop
{
public class _xobj
{
public string fieldName;
public List<_AllValue> fieldValues = new List<_AllValue>();
}
public class _AllValue
{
public string valueName;
public List<string> Values = new List<string>();
}
}
</code>
mohsenb55
-- modified at 10:07 Friday 15th June, 2007
|
|
|
|
|
mohsenb55 wrote: static void popxmlobj1(_xobj xobj)
{
_AllValue aValue1 = new _AllValue();
aValue1.valueName = "VAL1Name";
aValue1.Values.Add("Val1");
xobj.fieldName = "FieldName1";
_AllValue aValue2 = new _AllValue();
xobj.fieldValues.Add(aValue2);
aValue2.valueName = "VAL2Name";
aValue2.Values.Add("Val2");
xobj.fieldValues.Add(aValue2);
}
This code adds aValue2 to xobj twice, I assume this is not right ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Christian,
aValue2 is actually aValue1 I mistyped it. The problem is that I like to instantiate the _AllValue class only one time and re-use the same object multiple times. In the above code to get it to work, the _AllValue class is instantiated twice aValue1 and aValue2. I want to be able to re-use the same object, let's say _AllValue aValue = new _AllValue(); and re-use as many times I want too and not have to intantiate _AllValue twice.
Thanks for the response
|
|
|
|
|
I have a text file of the following format
"apple","orange","pear" etc
I have tried both char and string seperators but can't think of a way grab the data cleanly without including a " or , . I either end up with "apple" "orange" "pear" or "apple orange pear"
The code I have been using.
private static char[] charSeperator = new char[] { ',' };
private static string[] strSeperator = new string[] {"\",\""};
strArray = strLine.Split(charSeperator);
strArray = strLine.Split(strSeperator,StringSplitOptions.None);
Is there a simple way of grabing apple orange and pear from the text file, without having to do further data cleaning?
Thanks in advance for any help you can offer
Haz
|
|
|
|
|
You may want to try regular expressions...
"too much daily WTF for someone..." - Anton Afanasyev
|
|
|
|
|
Sorry Paul what do you mean by regular expressions? I'm only fairly new to this c#
Haz
|
|
|
|
|
|
Giorgi Dalakishvili wrote: http://www.regular-expressions.info/[
That looks like a bookmark worthy site to me
"too much daily WTF for someone..." - Anton Afanasyev
|
|
|
|
|
haz13 wrote: what do you mean by regular expressions? I'm only fairly new to this c#
Being new is cool. Regular expressions are a finite state automaton that work with search patterns, etc.
Take a look at this article:
Expresso[^]
"too much daily WTF for someone..." - Anton Afanasyev
|
|
|
|
|
Thanks for that info guys, I'll go away and have a read up on it
Haz
|
|
|
|
|
using System.Text.RegularExpressions; // the namespace for using Substring
strArray = strLine.Split(new char[] { ',' }; // Use this still, but with the modifications below
foreach (string fruit in strArray) // a loop that runs for every piece of fruit in strArray
{
int fruitlength = fruit.Length; // getting the length of the fruit string
fruitlength = fruitlength - 2; // subtracting 2 because of quotes
string trimmedfruit = fruit;
trimmedfruit = fruit.Substring(1,fruitlength);
// basically the method Substring(start,length)
// and the first letter starts at 0 and length is how many you want to cut out
// so I took the total length of string "apple", subtracted 2 because of quotes
// then started the trim at 1 just after the first qoute and pulled out all the letters
// minus the qoutes
}
|
|
|
|