|
Sorry About that
i put it all here
<br />
<br />
[Serializable]<br />
class GraphicsPathData<br />
{<br />
byte[] types;<br />
PointF[] points;<br />
FillMode fillMode;<br />
<br />
public GraphicsPathData(GraphicsPath gp)<br />
{<br />
this.types = gp.PathTypes;<br />
this.points = gp.PathPoints;<br />
this.fillMode = gp.FillMode;<br />
}<br />
<br />
public static System.IO.Stream Serialize(GraphicsPathData gpd)<br />
{<br />
System.IO.MemoryStream ms=new System.IO.MemoryStream();<br />
<br />
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();<br />
<br />
bf.Serialize(ms, gpd);<br />
ms.Flush();<br />
return ms;<br />
}<br />
<br />
public static GraphicsPathData Deserialize(System.IO.Stream stream)<br />
{<br />
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();<br />
<br />
object obj=bf.Deserialize(stream);<br />
GraphicsPathData gpd =obj as GraphicsPathData;<br />
return gpd;<br />
}<br />
<br />
public static GraphicsPath GetGraphicsPath(GraphicsPathData gpd)<br />
{<br />
return new GraphicsPath(gpd.points, gpd.types, gpd.fillMode);<br />
}<br />
<br />
public static GraphicsPath GetGraphicsPath(System.IO.Stream gpdStream)<br />
{<br />
return GetGraphicsPath(Deserialize(gpdStream));<br />
}<br />
}<br />
<br />
and I tested that like
<br />
<br />
GraphicsPath gp = new GraphicsPath();<br />
gp.AddEllipse(10, 10, 100, 100);<br />
<br />
GraphicsPathData gpd = new GraphicsPathData(gp);<br />
System.IO.Stream gpdStream = GraphicsPathData.Serialize(gpd);<br />
<br />
<br />
System.IO.Stream newStream = new System.IO.MemoryStream(((System.IO.MemoryStream)gpdStream).ToArray());<br />
<br />
GraphicsPath gpDeserialized = GraphicsPathData.GetGraphicsPath(newStream);<br />
<br />
|
|
|
|
|
Oh MAN!
You are king. Thanks a ton. This is almost exactly what I['m trying to do too...lol...So it works out perfectly!
Only now to code the saving to file...
|
|
|
|
|
Hey, thanks for the great reply at http://www.codeproject.com/script/comments/forums.asp?forumid=1649&fr=126&select=2170482&df=100&mpp=50&msg=2170482
However if i got an 3 arraylist to be serialize, one of them is an arraylist containing graphicspath, how do i deserialize them back to the 3 different arraylist. Should i save the number of items in each of the arraylist?
Below is how i put all the arraylist into a single arraylist
ArrayList arr = new ArrayList();
arr.Add(Arraylist1);//arraylist containing Point[]
for(int i=0;i
{
GraphicsPathData gpd = new GraphicsPathData((GraphicsPath)PathList[i]);
Stream gpdStream = GraphicsPathData.Serialize(gpd);
arr.Add(gpdStream);
}
arr.Add(Arraylist1);//arraylist containing enum
formatter.Serialize(myStream, arr);
myStream.Close();
What other method do you suggest?
Thanks in advance
|
|
|
|
|
I send a post to Graphicspath serialization for you.
|
|
|
|
|
So you have provided me with some fantastic help. Although I'm once again at a loss.
Now that I have a Serialized Stream, how do I save it to a file?
|
|
|
|
|
if you don't need your Stream after serialization process you can simply use FileStream instead of MemoryStream and directly save it to the disk.
but if you need your stream so you can save it using StreamWriter Class
<code>
void SaveToDisk(string path, Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
using (StreamWriter sw = new StreamWriter(path))
using (StreamReader sr = new StreamReader(stream))
{
sw.Write(sr.ReadToEnd());
sw.Flush();
}
}
</code>
if you had problem with StreamWriter and Reader you can use BinaryWriter and Reader (a little bit harder to use but I don't think you need them)
good Luck my Friend
|
|
|
|
|
I have developed a small database software in .Net 2.0 which has backend as Sql Server Express2005.Both of the server and client are running Windows XP. My client successfully detects the server but when connecting to the server, it displays the error message "Cannot
generate SSPI context".
I have also searched the internet but couldnot find any good solutions.
Could you people have any solution for this terrible error?
Help appreciated in both VB.Net and C#.
X
|
|
|
|
|
Probably should post this in the SQL / ADO / ADO.NET section... If you go over to that forum and search for SSPI, you might even get some answers. The 5th search down should have the answer you're looking for.
Hogan
|
|
|
|
|
I usually get this error when our domain controller cannot be reached while trying to access a SQLServer DB.
Don't know what to do about it, though...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hello,
I'm hoping someone can help me determine how a file is encoded when I read it in c#.
I'm reading in thousands of files that stretch over a couple of decades, and the files seem to keep changing their encryption.
the files are comma delimited and they have a header record.
I'm using the column names in the header record to create a column mapping for SqlBulkCopy, this is because over the years column names have changed or new columns have been added.
My program stops if an unrecognised column name is found and then I can check it and enter it into a mapping table.
However I'm occasionally getting strange characters in the column headings. I initially got around this problem by determing the encoding (using the peice of code at the end of the message) however I still seem to be coming across files where I can't tell what the encoding is and I'm getting strange characters (mainly when a "£" sign is not recognised).
I'm reading the file using this
using (StreamReader sr = new StreamReader(sourceFile, Encoding(sourceFile), true)
Can anyone help with this, I would be happy to replace unrecgognised characters if possible.
--------determine the type of encoding----
public static System.Text.Encoding Encoding(string sourceFile)
{
System.IO.FileStream file = null;
System.Text.Encoding enc = System.Text.Encoding.ASCII;
try
{
file = new System.IO.FileStream(sourceFile,
FileMode.Open, FileAccess.Read, FileShare.Read);
if (file.CanSeek)
{
byte[] bom = new byte[4]; // Get the byte-order mark, if there is one
file.Read(bom, 0, 4);
if ((bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf) || // utf-8
(bom[0] == 0xff && bom[1] == 0xfe) || // ucs-2le, ucs-4le, and ucs-16le
(bom[0] == 0xfe && bom[1] == 0xff) || // utf-16 and ucs-2
(bom[0] == 0 && bom[1] == 0 && bom[2] == 0xfe && bom[3] == 0xff)) // ucs-4
{
enc = System.Text.Encoding.Unicode;
}
else
{
enc = System.Text.Encoding.ASCII;
}
// Now reposition the file cursor back to the start of the file
file.Seek(0, System.IO.SeekOrigin.Begin);
}
else
{
enc = System.Text.Encoding.ASCII;
}
// Close the file: never forget this step!
file.Close();
return enc;
}
--------determine the type of encoding end----
Sean
|
|
|
|
|
Hi,
I trust recent files with a BOM (byte order mask) pose no problems ?
I expect problems to exist on older files that used ASCII/ANSI or some special "code page"
to accomodate whatever special requirement existed at the time (such as the pound sign.
Seems to me you should try to classify your files in a few groups, by symptom,
and then solve it for each group individually; I dont expect there to be a ready-made
solution since what you encounter probably is ad-hoc solution attempts to small encoding
problems.
For files without BOM I often find it useful to build a histogram for the byte values,
then print out the counts that are not zero and correspond to special values (say
verything above 0x7E).
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks for this, I'll try addressing it by groups of files.
Sean
|
|
|
|
|
Hi all,
I really hope there is a simple and good solution for my problem. I'm opening a .jpg image (640 x 480 pixels / 96 x 96 dpi / 24 bit depth / 30kb) using Image.FromFile(); After that i'm creating a thumbnail using
GetThumbnailImage(298, 160, dummyCallBack, IntPtr.Zero);
thumbNailImg.save(location, ImageFormat.Png);
This results in a .png image (298 x 168 pixels / 178 x 134 dpi / 32 bit depth / 90kb). But as result i want a smaller (compressed) png image with the following attributes: 298 x 168 pixels, 71dpi, 24 bits depth. How can this be done? I've been looking all over the internet but didn't find any good solution.
Anyone who can help me out? Thanks in advance!
|
|
|
|
|
You can set get these things through various Image properties -- HorizontalResolution, VerticalResolution, PixelFormat.
These may take a few attempts to get it the way you want, but I'm sure with a bit of effort you'll be able to do it.
Edit: SetResolution to change the Horizontal and VerticalResolution, PixelFormat is set during the constructor for the bitmap.
-- modified at 10:30 Monday 6th August, 2007
|
|
|
|
|
Those attributes are read-only....
|
|
|
|
|
Resolutions can be changed through the SetResolution method. PixelFormat must be set in the constructor.
|
|
|
|
|
Thnx!
I've changed the way i created the png image to the one you mentioned. Now i can create an empty Bitmap with the requered attributes en 'paste' te original into it.
|
|
|
|
|
how can read information within excel file from C# application
Palestine
|
|
|
|
|
What u mean.....?
Describe little more...
So i can help u?
Nisar Inamdar.
Always for u...
|
|
|
|
|
see this excel file
http://paltareq.brinkster.net/down/complete_apps_rep.xls
in my c# application i want to make for loop to read each cell in the file ?
Palestine
|
|
|
|
|
|
You can use the OleDb Managed Data Provider to read an Excel Spreadsheet using ADO.NET and C#
|
|
|
|
|
You can use InterOp service provided by Microsoft using Excel namespace.
namespace for Excel is,
Microsoft.Office.Interop.Excel
|
|
|
|
|
Hi Bhavesh,
Just a gentle suggestion.
This solution needs that you either assumes Office to be installed in the machine or you have to distubute the office libraries along with the Apps.
Please find my last post for this question it sould provide a better and faster solution.
laddie
|
|
|
|
|
TAREQ
Try this
using System.Data.OleDb;
using System.Data;
.
.
//I am not sure giving url in the filename will work.Please check it
OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+fileName+@";Extended Properties=""Excel 8.0;HDR=YES""");
oleConenction.Open();
OleDbCommand cmd= new OleDbCommand("select * from [Sheet1$]",oleConnection);
OleDbDataReader read = cmd.ExecuteReader();
while(read.Read())
{
Console.WriteLine(read[0]+......);
}
Please let me know if it helps
Laddie
}
|
|
|
|