Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Very frustrated. . . this should not be hard.

I have a font as an embedded resource in my program. I think the problem is that I cannot access it to get the size in bytes (if that is possible). I think that I need to put the font into the byte array to write it to disk but I cannot get it's attributes or access it.

Here is what I have so far:

 

FileStream FS=new FileStream("C:\\Windows\\verdana.ttf", FileMode.Create, FileAccess.Write);
		ResourceWriter RW=new ResourceWriter(FS);
		RW.AddResource("verdana.ttf", "1");
		RW.Close();
		byte[]b= new Byte[200];
		FS.Write(b, 0, 200);
		FS.Close();

Edited by divil
C#
Posted

i'm not totally sure what you are trying to do but this may help

 

System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("filename including namespace if it is different than default")

use GetNames method to find out the name of your file

 

this is probably not what you need but it might help

i'm not lazy i'm just resting before i get tired.
Posted

This is actually closer to what I am trying to do:

 

ResourceManager RM=new ResourceManager(typeof(Form1));

object font= RM.GetObject("verdana.ttf");

MessageBox.Show(""+font.ToString());

BinaryFormatter B=new BinaryFormatter();

B.Serialize(FS, font);

FS.Close();

 

My only trouble is referencing the embedded resource named, "verdana.ttf". I noticed that VS uses the Resource manager to load pictures into picture boxes. I cannot find where the resource is though. For example, my embedded resource is in the solution explorer with all the classes but theirs I cannot find anywhere. This is what is written in the code to load it:

 

this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));

 

How can I make a reference to my embedded resource that is shown in the Solution explorer?

C#
  • *Gurus*
Posted

I was able to accomplish this (with verdana.ttf embedded) like this:

 

FileStream f = new FileStream(@"c:\verdana.ttf", FileMode.Create);
Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsApplication7.verdana.ttf");
byte b;
int i;

while (true)
{
i = s.ReadByte();
   if (i == -1) break;
b = (byte)i;

f.WriteByte(b);
}

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
You're right divil. That did work. Forget that recource manager. Thank you so much. Why does it have to be so complicated like that? I think MS could have made that alot easier. After all, the object is right there!!
C#
  • *Gurus*
Posted

Yes, you do it in chunks at a time instead of byte by byte:

 

FileStream f = new FileStream(@"c:\verdana.ttf", FileMode.Create);
Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsApplication7.verdana.ttf");
byte[] b = new byte[4096];
int i;

while (true)
{
i = s.Read(b, 0, 4096);
if (i == 0) break;

f.Write(b, 0, i);
}

f.Close();

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
Actually I think I was wrong. . .there SEEMS to be no difference in speed. But, would you say that using a byte[] buffer is the best way to go, Rather than byte by byte?
C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...