TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
manuel
NA
68
0
CF_ENHMETAFILE image quality
Jul 13 2017 7:52 PM
Hi how can i get a good qualaty of image in geting image from clipboard..
is there another way..
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);
// Metafile mf is set to a state that is not valid inside this function.
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();
// invalidates mf
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);
// 14 == CF_ENHMETAFILE
bResult = hRes.Equals(hEMF2);
CloseClipboard();
}
}
}
DeleteEnhMetaFile(hEMF);
}
return bResult;
}
public static Image GetEnhMetafileFromClipboard(IntPtr hWnd)
{
OpenClipboard(hWnd);
// IntPtr.Zero
IntPtr hemf = GetClipboardData(14);
// 14 == CF_ENHMETAFILE
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;
}
Reply
Answers (
0
)
connect web api to ionic by push notiification?
invoke a f=button in form from a usercontrol