|
Use a LockBits method.
You should get something like this:
unsafe static byte[] getBytes(BitmapData data)
{
byte* firstByte = (byte*)data.Scan0.ToPointer();
int size = data.Stride * data.Height;
byte[] bytes = new byte[size];
for (int i = 0; i < size; i++)
bytes[i] = firstByte[i];
return bytes;
}
unsafe static void setBytes(BitmapData data, byte[] bytes)
{
byte* firstByte = (byte*)data.Scan0.ToPointer();
int size = data.Stride * data.Height;
for (int i = 0; i < size; i++)
firstByte[i] = bytes[i];
}
static void Main()
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(@"test.bmp")) {
BitmapData data = bmp.LockBits(new Rectangle(new Point(0), bmp.Size),
ImageLockMode.ReadOnly, bmp.PixelFormat);
byte[] bytes = getBytes(data);
bmp.UnlockBits(data);
using (Bitmap copy = new Bitmap(data.Width, data.Height, bmp.PixelFormat)) {
data = copy.LockBits(new Rectangle(new Point(0), copy.Size),
ImageLockMode.WriteOnly, copy.PixelFormat);
setBytes(data, bytes);
copy.UnlockBits(data);
copy.Save(@"test - copy.bmp");
}
}
}
Compile with /unsafe .
This code copies a BMP file. Insted getBytes and setBytes you may want to use System.Runtime.InteropServices.Marshal.Copy method, but it has many function we don't need here so it's better to stick to a simplier version.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Hi I've used the following Code to read Mail from a pop server In the UI when I enter the Server name as "smtpx14.msoutlookonline.net" and username as "X" and Password as "Confindent", it says the status as "220 exsmtp014-3.exch014.msoutlook.online.net Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at mon 21 jul 08 22:29
530 5.7.0 must issue a STARTTLS command first
530 5.7.0 must issue a STARTTLS command first
530 5.7.0 must issue a STARTTLS command first "
could some one assist me in fixing this out
Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Web.Mail;
namespace POPapp
{
///
/// Summary description for Form1.
///
public class POPForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox POPServ;
private System.Windows.Forms.TextBox User;
private System.Windows.Forms.TextBox Passw;
private System.Windows.Forms.RichTextBox Message;
private System.Windows.Forms.Button ConnectBtn;
private System.Windows.Forms.Button DisconnectBtn;
private System.Windows.Forms.ListBox Status;
private System.Windows.Forms.Button RetrieveBtn;
private System.Windows.Forms.TextBox Number;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public POPForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.Number = new System.Windows.Forms.TextBox();
this.Status = new System.Windows.Forms.ListBox();
this.label4 = new System.Windows.Forms.Label();
this.Message = new System.Windows.Forms.RichTextBox();
this.label6 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.ConnectBtn = new System.Windows.Forms.Button();
this.POPServ = new System.Windows.Forms.TextBox();
this.User = new System.Windows.Forms.TextBox();
this.DisconnectBtn = new System.Windows.Forms.Button();
this.Passw = new System.Windows.Forms.TextBox();
this.RetrieveBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// Number
//
this.Number.Location = new System.Drawing.Point(80, 296);
this.Number.Name = "Number";
this.Number.Size = new System.Drawing.Size(56, 20);
this.Number.TabIndex = 12;
this.Number.Text = "";
//
// Status
//
this.Status.Location = new System.Drawing.Point(8, 344);
this.Status.Name = "Status";
this.Status.Size = new System.Drawing.Size(392, 56);
this.Status.TabIndex = 16;
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 96);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(64, 16);
this.label4.TabIndex = 7;
this.label4.Text = "Message";
//
// Message
//
this.Message.Location = new System.Drawing.Point(8, 112);
this.Message.Name = "Message";
this.Message.Size = new System.Drawing.Size(392, 176);
this.Message.TabIndex = 6;
this.Message.Text = "";
this.Message.WordWrap = false;
//
// label6
//
this.label6.Location = new System.Drawing.Point(8, 328);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(100, 16);
this.label6.TabIndex = 15;
this.label6.Text = "Status";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "POP Server";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 40);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "User";
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 64);
this.label3.Name = "label3";
this.label3.TabIndex = 2;
this.label3.Text = "Password";
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 296);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 16);
this.label5.TabIndex = 11;
this.label5.Text = "Mail Number";
//
// ConnectBtn
//
this.ConnectBtn.Location = new System.Drawing.Point(328, 16);
this.ConnectBtn.Name = "ConnectBtn";
this.ConnectBtn.TabIndex = 8;
this.ConnectBtn.Text = "Connect";
this.ConnectBtn.Click += new System.EventHandler(this.ConnectBtn_Click);
//
// POPServ
//
this.POPServ.Location = new System.Drawing.Point(80, 16);
this.POPServ.Name = "POPServ";
this.POPServ.Size = new System.Drawing.Size(224, 20);
this.POPServ.TabIndex = 3;
this.POPServ.Text = "pop.server.com";
//
// User
//
this.User.Location = new System.Drawing.Point(80, 40);
this.User.Name = "User";
this.User.Size = new System.Drawing.Size(224, 20);
this.User.TabIndex = 4;
this.User.Text = "user";
//
// DisconnectBtn
//
this.DisconnectBtn.Enabled = false;
this.DisconnectBtn.Location = new System.Drawing.Point(328, 48);
this.DisconnectBtn.Name = "DisconnectBtn";
this.DisconnectBtn.TabIndex = 9;
this.DisconnectBtn.Text = "Disconnect";
this.DisconnectBtn.Click += new System.EventHandler(this.DisconnectBtn_Click);
//
// Passw
//
this.Passw.Location = new System.Drawing.Point(80, 64);
this.Passw.Name = "Passw";
this.Passw.PasswordChar = '*';
this.Passw.Size = new System.Drawing.Size(224, 20);
this.Passw.TabIndex = 5;
this.Passw.Text = "password";
//
// RetrieveBtn
//
this.RetrieveBtn.Enabled = false;
this.RetrieveBtn.Location = new System.Drawing.Point(152, 296);
this.RetrieveBtn.Name = "RetrieveBtn";
this.RetrieveBtn.TabIndex = 10;
this.RetrieveBtn.Text = "Retrieve";
this.RetrieveBtn.Click += new System.EventHandler(this.RetrieveBtn_Click);
//
// POPForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(408, 405);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.Status,
this.label6,
this.Number,
this.label5,
this.RetrieveBtn,
this.DisconnectBtn,
this.ConnectBtn,
this.label4,
this.Message,
this.Passw,
this.User,
this.POPServ,
this.label3,
this.label2,
this.label1});
this.MaximizeBox = false;
this.Name = "POPForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Download Mail via POP3";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new POPForm());
}
private void ConnectBtn_Click(object sender, System.EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
// create server POP3 with port 110
Server = new TcpClient(POPServ.Text,25);
Status.Items.Clear();
try
{
// initialization
NetStrm = Server.GetStream();
RdStrm = new StreamReader(Server.GetStream());
Status.Items.Add(RdStrm.ReadLine());
// Login Process
Data = "USER " + User.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());
Data = "PASS " + Passw.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());
// Send STAT command to get information ie: number of mail and size
Data = "STAT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());
// change enabled - disabled button
ConnectBtn.Enabled = false;
DisconnectBtn.Enabled = true;
RetrieveBtn.Enabled = true;
// back to normal cursor
Cursor.Current = cr;
}
catch (InvalidOperationException err)
{
Status.Items.Add("Error: " + err.ToString());
MessageBox.Show(err.Message);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
private void DisconnectBtn_Click(object sender, System.EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
// Send QUIT command to close session from POP server
Data = "QUIT"+CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
Status.Items.Add(RdStrm.ReadLine());
//close connection
NetStrm.Close();
RdStrm.Close();
// change enabled - disabled button
ConnectBtn.Enabled = true;
DisconnectBtn.Enabled = false;
RetrieveBtn.Enabled = false;
// back to normal cursor
Cursor.Current = cr;
}
private void RetrieveBtn_Click(object sender, System.EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
string szTemp;
Message.Clear();
try
{
// retrieve mail with number mail parameter
Data = "RETR "+ Number.Text+CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
szTemp = RdStrm.ReadLine();
if(szTemp[0]!='-')
{
while(szTemp!=".")
{
Message.Text += szTemp+CRLF;
szTemp = RdStrm.ReadLine();
}
}
else
{
Status.Items.Add(szTemp);
}
// back to normal cursor
Cursor.Current = cr;
}
catch(InvalidOperationException err)
{
Status.Items.Add("Error: "+err.ToString());
}
}
public TcpClient Server;
public NetworkStream NetStrm;
public StreamReader RdStrm;
public string Data;
public byte[] szData;
public string CRLF = "\r\n";
}
}
Thanks in Advance.......
Regards,
Kathir
|
|
|
|
|
Post the relevant code, not the entire project.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hii..i have sqldatabase from which the data is being displayed in gridview fields and i am performing edit delete operations using the link buttons.and finally i want to dispaly the record of a single row in color format but i am unable to do so.and gridview fields are boun ddata fields.plz help me out.
santosh
|
|
|
|
|
You can use the "RowCreated" event to find the row and set background color.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string id = GridView1.DataKeys[e.Row.RowIndex].ToString();
if (id = "test")
{
e.Row.BackColor = "pink";
}
}
}
|
|
|
|
|
Hello everyone,
Suppose I have an URL, and I want to get the domain part, for example, URL is, http://abc.com/some/address/abc.html, the domain is abc.com.
My questions are,
- Are there any existing utility class to do this? Not all URLs begins with protocol part, like http://, and not all ends with /, so I feel hard when I try to write a parser by myself;
- Is domain case sensitive or not? i.e. abc.com the same as ABc.Com?
thanks in advance,
George
|
|
|
|
|
Domains aren't case sensitive. abc.com is the same as ABc.Com. If you're comparing, just lower case it.
Use a regular expression for the domain part. Protocol doesn't matter. You're just interested in the domain name. From there, you can build a URL and validate it. Anything after a / is content, as per your example.
|
|
|
|
|
Thanks Bert!
Are there any existing regular expression to make a reference? I think it should be a common problem.
regards,
George
|
|
|
|
|
George_George wrote: Are there any existing utility class to do this? Not all URLs begins with protocol part, like http://, and not all ends with /, so I feel hard when I try to write a parser by myself;
Yes. System.Net.Uri class does this.
Uri uri = new Uri("http://abc.com/some/address/abc.html");
Console.WriteLine(uri.Host);
George_George wrote: Is domain case sensitive or not? i.e. abc.com the same as ABc.Com?
Usually domains are not case sensitive. But some web servers like APACHE, consider the folder names as case sensitive. Which means, www.abc.com will be equal to www.ABC.com , but www.abc.com/somefolder won't be equal to www.abc.com/SomeFolder according to apache.
|
|
|
|
|
Cool, N a v a n e e t h!
I like your solution.
regards,
George
|
|
|
|
|
Hello everyone,
Suppose I have a Dictionary object instance, Dictionary<string, int>, the int is always positive. I want to get top 10 elements from the Dictionary with the maximum 10 int values, any efficient way to do this?
thanks in advance,
George
|
|
|
|
|
George_George wrote: I want to get top 10 elements from the Dictionary with the maximum 10 int values,
it's not clear. Can you explain it ?
|
|
|
|
|
Sorry for my English, N a v a n e e t h!
Here is a sample, suppose I have a dictionary <string,>. Here is a sample content,
("entry1", 1);
("entry2", 2);
("entry3", 3);
("entry4", 10);
("entry5", 5);
then top 2 (from the value of key/value pair point of view) is entry 4 and entry 5. I want to retrieve top 10, any efficient solutions?
regards,
George
|
|
|
|
|
Oh, so by top, you actually mean bottom?
Perhaps something like:
int[] values = list.Values.ToArray();
values.Sort();
int tr = values[values.Length - 10];
List<KeyValuePair<string,int>> = list.Where(item=>item.Value>=tr).ToList();
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
I am sorting a Dictonary< , > but you are sorting a List<>? I am confused about your code? For your code list.Values.ToArray(), where does the list variable comes from?
regards,
George
|
|
|
|
|
Sorry about the confusing name. The list variable is the dictionary...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa!
I read your code again, but confused about the following statement.
1.
From left side of the assignment, do you miss a variable name?
2.
What does this operator mean <ptr>item=>item.Value>=tr?
List<KeyValuePair<string,int>> = list.Where(item=>item.Value>=tr).ToList();
regards,
George
|
|
|
|
|
George_George wrote: From left side of the assignment, do you miss a variable name?
Correct.
George_George wrote: What does this operator mean item=>item.Value>=tr?
It's a lambda expression. When it's not turned into an expression object it's equivalent to a delegate, which you can use if you don't have C# 3:
delegate(KeyValuePair<string,int> item){ return item.Value >= tr; }
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
I read and studied again about your pseudo code, I think it has good idea. But my current confusion is, there is no members called "where" as you used in your sample.
I am using C# 2.0, and can not use other version, like C# 3.
It is appreciated if you could re-write your sample code to make your ideas more clear?
regards,
George
|
|
|
|
|
Ok, then you have to do it the old fashoned way:
int[] values = dictionary.Values.ToArray();
values.Sort();
int tr = values[values.Length - 10];
List<KeyValuePair<string,int>> result = new List<KeyValuePair<string,int>>();
foreach (KeyValuePair<string,int> item in dictionary) {
if (item.Value >= tr) {
result.Add(item);
}
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
Smart!
regards,
George
|
|
|
|
|
Quickly, off the top of my head, you could create a linked list of objects with which you will do an insertion sort. You then run the dictionary, inserting objects into the array ONLY if the value is higher than the value at position zero OR if the array is empty. When inserting a new object, just insert it in the correct place.
Wow, I was being exceptionally thick tonight. I just realized that you could just use an OrderedDictionary.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
modified on Tuesday, July 22, 2008 2:56 AM
|
|
|
|
|
Thanks Joe,
This is what I am doing currently, I think this approach is manual and I want to find whether there are some existing classes/APIs could do this -- sort by value or key/value pair?
regards,
George
|
|
|
|
|
Hello All--
I have a List<double[]> Values, where each double[] is an array representing one series (not from a database). I can have several dozen double[] and each can be 100k+ items.
I would like to display this to the user in a datagrid (I know this is a lot of information, but the user needs to be able to browse). Due to the size, it is prohibative to load the entire thing into the grid at once, instead loading rows as needed. From Google, it seems like I need to bind this data source to the datagrid.
I've tried this:
currencyManager = (CurrencyManager)dataGridViewData.BindingContext[Data.Values];
dataGridViewData.DataSource = Data.Values;
But this displays the property of each List<> item (the double[]) in the grid (length, rank, etc).
Any suggestions on how to properly bind this data source?
Thanks
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Hi all...
this is for an chat application....
i want to get system ideal time for setting the user status to ideal in the chat....
supposs if the system is ideal for 2 minut, I want to change the status of the logged in user to Ideal.
so can anyone help me to solve this problem....
Thanks in Advance
Vayanan
|
|
|
|
|