|
Hi Collin,
if you want to convert an existing image into a stream, use an Image.Save overload that deals with streams i.e. Image.Save(Stream, ImageFormat).
the code you have shown does NOT deal with an image, it only handles pixel data; I suggest you don't try and convert pixel data back into a valid image, just use the existing .NET classes (Image, Bitmap), they know about several image formats.
FWIW: if you are having trouble turning an image into a stream (say a MemoryStream), then reading it back from that stream, chances are you forgot to "rewind" the stream between writing and reading, i.e. to reposition it at its beginning.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
You can use the System.IO.MemoryStream object to do this.
byte[] buffer;
MemoryStream ms=new MemoryStream(buffer);
Hope this helps.
|
|
|
|
|
|
Post the exception type and exception message.
|
|
|
|
|
Hi,
I am trying to get some rich text (from a RichTextBox.Rtf) onto a bitmap but can't seem to find a way to do it.
The key lines of my code are...
Bitmap Canvas = new Bitmap(200, 200, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics Artist = Graphics.FromImage(Canvas);
Artist.PageUnit = GraphicsUnit.Pixel;
Artist.DrawString("Hello", descFont, descBrush, rect, descFormat);
It would have been nice if there were a:
Graphics.DrawRTF(string richText, Rectangle rect)
method, but there isn't.
What is usually done as a replacement? Any help or pointers appreciated.
Regards,
David Bailey.
|
|
|
|
|
Whats wrong with the 4 lines of code you already posted?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi musefan,
I am trying to display RichText not plain text. Or are you saying that the DrawString() command handles rich text as well?
-David.
|
|
|
|
|
No, DrawString() will not auto handle your formatting.
Have a look at this[^] for some ideas.
You could always handle yourself by iterating through each word in the richtextbox then getting its formatting(color, font etc.) before drawing it to the graphics object.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thanks.
I did not think to loop though the rich text. Might just do that.
The link was useful too.
-David.
|
|
|
|
|
Hi.. Am new to C# and our director gave a project.
Basically, what i want to do is launch an external program and place it within my c# app so when i maximize it, it just maximize within my app. I know how to launch an external program. What i want to know is it is possible to place the launched program in a child form for example.
Any help would be appreciated. Thanks..
|
|
|
|
|
There's an article on here called Windows Tabifier[^] that does what you want.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi,
how can i open an existing excel file as a new document.
and if user close it from upper left close(X) button of doc,
then it should ask to save the document as a new excel doc file.
amit
modified on Friday, March 20, 2009 7:57 AM
|
|
|
|
|
Hi,
I need to loop over a class' properties(object.GetType().GetProperties()), and if the property implements IEnumerable I need to respond to that, but I cannot find a way to confirm this, any ideas?
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
You'll need to have a check that gets the type of the properties and then checks which interfaces it implements. Something like:
<br />
Type[] ifaces = field.GetType().GetInterfaces()<br />
if (ifaces.Contains(typeof(IEnumerable))<br />
{<br />
}<br />
where field is the property you're looking at.
This might be better implemented as a recursive function if you have a deep object tree.
It definitely isn't definatley
|
|
|
|
|
Great, thanks. Took me a while to figure out what the results were but makes sense.
Now for the next challenge: For Generics collections you can do object.GetType().GetProperties()[0].PropertyType.GetGenericArguments()[0].Name for example to find out what object is contained by the enumerable, what would the equivalent be for an array?
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
If I've understood correctly, you need to look at the ElementType of the object:
<br />
int[] myarray = new int[10];<br />
Type arrayType = myarray.GetType().GetElementType();<br />
will return System.Int32
It definitely isn't definatley
|
|
|
|
|
Perfect, thanks for the help
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
Hi.
How can we add an icon to our control library ?
I mean , I want to change this icon[^]
Thank you.
|
|
|
|
|
You need the ToolboxBitmap attribute. A couple of issues with it that I've found.
It doesn't show at all if the control/component is in the same project.
If it's a component, it will only show the icon in the designer (not in the toolbox for either control or component) if it's in a seperate project in the same solution.
Works fine if the output dll is used as the reference!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Is this it :
[System.Drawing.ToolboxBitmap(typeof(WebCamCapture), "CAMERA.ICO")]
DaveyM69 wrote: It doesn't show at all if the control/component is in the same project.
So how can we set an icon to it ?
|
|
|
|
|
The below code is i tryed for ajax auto complete on my site..
plz say if their is any bugs...
default2.aspx
]]>
<title>
function IAmSelected(source, eventArgs) {
alert(" Key : " + eventArgs.get_text() + " Value : " + eventArgs.get_value());
}
<asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">
<services>
<asp:servicereference path="~/WebService.asmx">
<asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown">
<ajaxtoolkit:autocompleteextender id="AutoCompleteExtender1" runat="server" onclientitemselected="IAmSelected" xmlns:ajaxtoolkit="#unknown">
BehaviorID="AutoCompleteEx" TargetControlID="TextBox1" ServicePath="WebService.asmx" MinimumPrefixLength="3" EnableCaching="true" ServiceMethod="GetCompletionList">
autocomplete.cs
using System;
using System.Collections.Generic;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Services;
///
/// Summary description for WebService
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] GetCompletionList(string prefixText)
{
{
string sql = "select Aname From Pincode Where Aname like @prefixText";
SqlDataAdapter da = new SqlDataAdapter(sql, "Server=sql346.mysite4now.com;uid=aitts_85478;password=aitts;database=aitts_85478");
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
// List<string> items = new List<string>();
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["Aname"].ToString(), i);
//items.Add(dr["Location_Name"].ToString());
i++;
}
// return items.ToArray();
return items;
}
}
}
webservice.asmx
]]>
its not working for me....
|
|
|
|
|
First off there is an ASP.net forum that you may get more help with
Second please don't post so much code only the relevant problem areas
Third when posting code please use the code block then people can read it easier and follow the code.
and finally what error message are you getting?
|
|
|
|
|
Hi all,
Can someone tell me a way to add text and an image on a ListBox. Actually I want to add an icon in between text.
I can add text there, but stuck with the image.
Thanks all.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
You may be able to do it by setting DrawMode to one of the OwnerDraw modes and using the DrawItem event.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Sorry for disturbing.
Do you know any example link about that? If so please can you send it here.
I appreciate your help all the time...
CodingLover
|
|
|
|