|
No, but I've the answer.
With this metho I size the image to the wright size. You can put this method in a seperate class.
<br />
public Image FixedSize(Image imgPhoto, int Width, int Height)<br />
{<br />
int sourceWidth = imgPhoto.Width;<br />
int sourceHeight = imgPhoto.Height;<br />
int sourceX = 0;<br />
int sourceY = 0;<br />
int destX = 0;<br />
int destY = 0;<br />
<br />
float nPercent = 0;<br />
float nPercentW = 0;<br />
float nPercentH = 0;<br />
<br />
nPercentW = ((float)Width / (float)sourceWidth);<br />
nPercentH = ((float)Height / (float)sourceHeight);<br />
<br />
<br />
if (nPercentH < nPercentW)<br />
{<br />
nPercent = nPercentH;<br />
destX = (int)((Width - (sourceWidth * nPercent)) / 2);<br />
}<br />
else<br />
{<br />
nPercent = nPercentW;<br />
destY = (int)((Height - (sourceHeight * nPercent)) / 2);<br />
}<br />
<br />
int destWidth = (int)(sourceWidth * nPercent);<br />
int destHeight = (int)(sourceHeight * nPercent);<br />
<br />
Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);<br />
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);<br />
<br />
Graphics grPhoto = Graphics.FromImage(bmPhoto);<br />
grPhoto.Clear(Color.White);<br />
grPhoto.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;<br />
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;<br />
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;<br />
grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;<br />
grPhoto.CompositingQuality = CompositingQuality.HighQuality;<br />
<br />
grPhoto.DrawImage(imgPhoto,<br />
new Rectangle(destX, destY, destWidth, destHeight),<br />
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),<br />
GraphicsUnit.Pixel);<br />
<br />
grPhoto.Dispose();<br />
return bmPhoto;<br />
}
The next thing I did was to create class that derive from printdocument.
The next part of code:
public class PrintImage : PrintDocument<br />
{<br />
private int currentPage;<br />
<br />
private int numberOfPages;<br />
<br />
private Image imageToPrint;<br />
<br />
public Image ImageToPrint<br />
{<br />
get<br />
{<br />
return this.imageToPrint;<br />
}<br />
<br />
set<br />
{<br />
this.imageToPrint = value;<br />
this.numberOfPages = this.imageToPrint.GetFrameCount(FrameDimension.Page);<br />
}<br />
}<br />
<br />
protected override void OnBeginPrint(PrintEventArgs e)<br />
{<br />
base.OnBeginPrint(e);<br />
<br />
this.currentPage = 0;<br />
<br />
if (this.imageToPrint == null)<br />
{<br />
throw new ArgumentNullException("ImageToPrint");<br />
}<br />
}<br />
<br />
protected override void OnPrintPage(PrintPageEventArgs e)<br />
{<br />
AfbeeldingFormaat afb = new AfbeeldingFormaat();;<br />
base.OnPrintPage(e);<br />
<br />
this.ImageToPrint.SelectActiveFrame(FrameDimension.Page, this.currentPage);<br />
<br />
using (var bmp = new Bitmap(this.imageToPrint))<br />
{<br />
Image image;<br />
<br />
image = afb.FixedSize(bmp, e.PageBounds.Width, e.PageBounds.Height);<br />
<br />
e.Graphics.DrawImage(image, e.PageBounds);<br />
<br />
e.HasMorePages = ++this.currentPage < this.numberOfPages;<br />
}<br />
}<br />
}
And then the last part to print.
<br />
PrintDocument printDocument = new PrintImage { ImageToPrint = Image.FromFile(path) };<br />
<br />
var ppd = new PrintDialog<br />
{<br />
Document = printDocument<br />
};<br />
<br />
if (ppd.ShowDialog() == DialogResult.OK)<br />
{<br />
<br />
printDocument.Print();<br />
<br />
}<br />
<br />
I hope this helps you.
|
|
|
|
|
A bit TMI, but your code does contain the answer, which is here (after selecting the active frame on the image, simply create a new bitmap from it and use that bitmap to print to the graphics object):
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
this.ImageToPrint.SelectActiveFrame(FrameDimension.Page, this.currentPage);
using (var bmp = new Bitmap(this.imageToPrint))
{
e.Graphics.DrawImage(bmp, e.PageBounds);
e.HasMorePages = ++this.currentPage < this.numberOfPages;
}
}
|
|
|
|
|
Hi,
How save a picture from a WebCam Stream to .bmp
The camera has a fixed resulution of 2MP.
I want to write it in C#.
thanks
|
|
|
|
|
Safe from what, the rain? just give it an umbrella
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You'll have to consult the documentation on the library you're using to get the video from the webcam.
|
|
|
|
|
Which documentation? I don't know how to start, which library should I take?
|
|
|
|
|
Contact the manufacturer of the webcam to see if they put out a SDK (Software Development Kit) that you can use. It should come with the libraries and the documentation on how to use them.
|
|
|
|
|
hello all can any body help me to convert class to dll file
|
|
|
|
|
Set project output type to Class Library
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)
|
|
|
|
|
|
Yeah Visual Studio can help you do that. i.e. you IDE would be the best place to start, you basically want to compile your project as a .DLL file
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Next time please do googling before posting any question
anyways here we go
use the following command from command prompt of visual studio
csc /target:library File.cs
if you are usinf visual studio IDE use following steps to do so
1.goto file->new ->project
2.select class library
3.Provide name to class library
4.click ok
4.write down your class in file opened
5.build the project
6.you will get your dll in path application dir/bin/debug
so simple
|
|
|
|
|
&Hello,
How we can send the e-mails witch c#? thank you verry mutch.
|
|
|
|
|
At least click me[^]
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
With MailMessage and SmtpClient.
MailMessage mm = new MailMessage("from", "to", "subject", "body");
SmtpClient sc = new SmtpClient("mail server", port);
sc.Send(mm);
|
|
|
|
|
abbd wrote: the e-mails witch
she sounds scary
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
nah my firewall is working...
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I think you need a 'waterwall' for witches
Unless you burn them at the stack!!!
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
abbd wrote: witch c#
Is this the upcoming version of C#? Where did you download it?
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
You can do somesing like this:
private string login = "test@ukr.net";
private string password = "test";
private string smtp_host = "smtp.ukr.net";
int port = 465;
public Mailer()
{
System.Net.Mail.SmtpClient mysmtp = new SmtpClient();
mysmtp.Host = smtp_host;
mysmtp.Port = port;
mysmtp.EnableSsl = true;
mysmtp.Credentials = new System.Net.NetworkCredential(login, password);
MailAddress from = new MailAddress("test@ukr.net", "user anonimus =)");
MailAddress to = new MailAddress("to@mathcentre.com.ua");
MailMessage msg = new MailMessage(from, to);
msg.Subject = "programm test";
msg.Body = "test!!!!!!!!!\n see ya!";
mysmtp.Send(msg); // this code works but I dont now how use certificates that
//used by some mail-servers =(
}
|
|
|
|
|
Hi everybody!
just wanted to ask a short question:
I have a property, that should be (externally) threadsafe. Is this good coding style, or do you have a better solution?
class Manager
{
private object locker = new object();
private MyType threadSafeProperty = new MyType();
public MyType ThreadSafeProperty
{
get { lock (locker) { return threadSafeProperty; } }
set { lock (locker) { threadSafeProperty = value; } }
}
}
Thank you, Phil
I won’t not use no double negatives.
|
|
|
|
|
AFAIK, "lock" is not recomended since it can result in permanent lockups of an object for ever.
Monitor.TryEnter does the same but takes an argument specifying timeout interval.
Also, the locker object should be readonly.
|
|
|
|
|
This will not work if your intent is to synchronize access to the MyType instance. You are only holding the lock while getting the reference to the instance. You then return the instance to the calling code which may then use it without synchronization.
The solution depends on what the calling code does with the MyType instance. You could expose a synchronization object in the Manager class, but that is open to abuse. Or you could add methods for manipulating the instance through the Manager class and use locks in those methods. YMMV.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thank you for you answer Nick.
That was actually why asked this, I had a bad feeling about that
MyType is some kind of generic List. I wanted to ensure that I had exclusive access to the list as long as I was manipulating it.
Stupid idea now
I will expose the lock and acquire it as long as I am manipulating the list.
Phil
I won’t not use no double negatives.
|
|
|
|
|