|
Hi how can i paste image to file?
my image is CF_ENHMETAFILE=14 image
Code below get image without quality how can i save image from clipboard to file.
Thank you
public class ClipboardMetafileHelper
{
[DllImport("user32.dll", EntryPoint = "OpenClipboard", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool OpenClipboard(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "EmptyClipboard", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EmptyClipboard();
[DllImport("user32.dll", EntryPoint = "SetClipboardData", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr SetClipboardData(int uFormat, IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "GetClipboardData", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr GetClipboardData(int uFormat);
[DllImport("user32.dll", EntryPoint = "CloseClipboard", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool CloseClipboard();
[DllImport("gdi32.dll", EntryPoint = "CopyEnhMetaFileA", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr CopyEnhMetaFile(IntPtr hemfSrc, IntPtr hNULL);
[DllImport("gdi32.dll", EntryPoint = "DeleteEnhMetaFile", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool DeleteEnhMetaFile(IntPtr hemfSrc);
public static bool PutEnhMetafileOnClipboard(IntPtr hWnd, Metafile mf)
{
bool bResult = new bool();
bResult = false;
IntPtr hEMF = default(IntPtr);
IntPtr hEMF2 = default(IntPtr);
hEMF = mf.GetHenhmetafile();
if (!hEMF.Equals(new IntPtr(0)))
{
hEMF2 = CopyEnhMetaFile(hEMF, new IntPtr(0));
if (!hEMF2.Equals(new IntPtr(0)))
{
if (OpenClipboard(hWnd))
{
if (EmptyClipboard())
{
IntPtr hRes = default(IntPtr);
hRes = SetClipboardData(14, hEMF2);
bResult = hRes.Equals(hEMF2);
CloseClipboard();
}
}
}
DeleteEnhMetaFile(hEMF);
}
return bResult;
}
public static Image GetEnhMetafileFromClipboard(IntPtr hWnd)
{
OpenClipboard(hWnd);
IntPtr hemf = GetClipboardData(14);
CloseClipboard();
if (hemf != IntPtr.Zero)
{
Metafile mf = new Metafile(hemf, true);
Bitmap b = new Bitmap(mf.Width, mf.Height);
Graphics g = Graphics.FromImage(b);
g.FillRectangle(Brushes.White, 0, 0, 1000, 1000);
GraphicsUnit unit = GraphicsUnit.Millimeter;
RectangleF rsrc = mf.GetBounds(ref unit);
g.DrawImage(mf, new Rectangle(0, 0, mf.Width, mf.Height), rsrc, unit);
return b;
}
return null;
}
}
|
|
|
|
|
|
thank you any good sample code?
|
|
|
|
|
Most likely, yes. But you will probably learn more by using the documentation.
|
|
|
|
|
Will give a try but it´s not easy for me
normal copy from clipboard work´s fine
if (Clipboard.ContainsImage())
{
picSample.Image = Clipboard.GetImage();
picSample.Visible = true;
picSample.Image.Save(@"c:\abc.png" );
for
CF_ENHMETAFILE=14 is the problem
|
|
|
|
|
|
after some seach i came to this solucion but quality image saved is very low please advise.
Metafile emf = null;
if (OpenClipboard(IntPtr.Zero))
{
if (IsClipboardFormatAvailable(CF_ENHMETAFILE))
{
var ptr = GetClipboardData(CF_ENHMETAFILE);
if (!ptr.Equals(IntPtr.Zero))
emf = new Metafile(ptr, true);
emf.Save(@"c:\image1.png");
}
CloseClipboard();
}
|
|
|
|
|
|
I'm having trouble using TLS1.2 with smtp.gmail.com and authenticating; gmail keeps saying that I'm not authenticating correctly.
Not sure if I'm using the ServicePointManager correctly at this point.
So I'm using smtp.gmail.com on port 587 with ssl enabled.
This is what I have. The SmtpClient runs first and picks up the credentials, the the SendEmailAsync runs and sends. The Catch catched the exception saying that I wasn't authenticated.
Scratching my head on this.
public static SmtpClient create_SMTPClient(smtp_credentials smtpC)
{
var smtpClient = new SmtpClient();
var smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
if (smtpSection == null)
{
smtpClient.UseDefaultCredentials = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
<pre>
var smtpCredentials = new System.Net.NetworkCredential() {
UserName = smtpC.smtp_AccountName,
Password = smtpC.smtp_Password
};
smtpClient.Credentials = smtpCredentials;
smtpClient.Host = smtpC.smtp_ServerUrl;
smtpClient.Port = smtpC.smtp_PortNumber;
smtpClient.EnableSsl = smtpC.smtp_PortNumber == 587 ? true : false;
smtpClient.Timeout = 250000;
}
if (smtpClient.Port == 587)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
if (smtpClient.Port == 443)
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidation_Callback;
return smtpClient;
}
public static async Task<SendEmailCompletedEventArgs> sendEmailAsync(SmtpClient smtpClient, MailMessage message, int retryCount)
{
int currentTry = 0;
while ((currentTry < retryCount))
{
try
{
await smtpClient.SendMailAsync(message);
return new SendEmailCompletedEventArgs(null, false, null, currentTry);
}
catch (Exception ex)
{
currentTry++;
if ((currentTry >= retryCount))
{
return new SendEmailCompletedEventArgs(ex, true, null, currentTry);
}
}
}
return new SendEmailCompletedEventArgs(null, true, null, currentTry);
}</pre>
If it ain't broke don't fix it
|
|
|
|
|
I think my issue here is I need to connect as TLS1.2 but it's connecting as TLS1.1, in which Gmail considers to be less secure.
So the Service point stepped down a notch and my code failed.
So I wonder if it's a cipher in my registry on SChannel or my protocols that I selected.
If it ain't broke don't fix it
|
|
|
|
|
Which OS? TLS1.2 was disabled by default prior to 8.1 / 2012 R2, and not available on Vista / 2008 or earlier.
You should be able to check whether it's enabled from the IE options dialog, on the "Advanced" page:
Support for SSL/TLS protocols on Windows – Unleashed[^]
AFAIK, those settings also affect .NET code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Developing on Win10 with VS2017.
I program the ServicePointManager, and in the SmtpClient it says the address threw an exception before I even call SendMailAsync
The after the SendMailAsync runs, the caught Exception says must StartTLS first.
My endpoint is smtp.gmail.com on 587 with ssl on and using .Net 4.6.1
Strange, but after calling SendEmailAsync, it reads the SmtpCreddentials again and call Send a 2nd time.
I think it works in my VB version using .Net 4.6.1
If it ain't broke don't fix it
|
|
|
|
|
I changed my Gmail account type to less secure and it works fine with the same settings.
I wonder what the difference is between secure and less secure, I mean the whole difference is.
I hear .Net 4.6.2 is suppose to fix this for secure app.
If it ain't broke don't fix it
|
|
|
|
|
how to make calculation based on the quantity that user key in with the data(column) in the excel file that we link in c# ?
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
What have you tried?
Where are you stuck?
What help do you need?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
ok. sorry 4 that. i just think maybe some of u have example that can be shared
|
|
|
|
|
It's possible we do - but if we have no idea what you are talking about (because you gave us no information) then it's unlikely that we can tell you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I'm trying to learn Rx. I have seen a lot of Google results and other resources pointing to this site.
Thing is, I'm just not getting it. What I'd really like to see is a simple, real world example. The code snippets in that site are VERY brief, not too deeply explained, and don't really show real work usage.
Does anyone know of any tutorials or real world usage examples of Rx?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi,
I can't help you, but maybe this can.
|
|
|
|
|
Already did that
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I would recommend starting off here before delving into the Rx book.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
|
Kevin Marois wrote: What I'd really like to see is a simple, real world example
My guess is that is an oxymoron.
If it is simple and you are using reactive extensions then someone is experimenting and not writing good code. It should rather be the case that there is a complex problem that needs a solution and reactive extensions are thus needed (in very limited cases.)
|
|
|
|
|
Hi. I want to know is it possible to play audio though online storage.
I have my website and I see am able to play music from my website form of my server storage what I transfer with filezilla.
I want to know can I do this using winforms
If so is there a source or a link
Thanks
|
|
|
|