Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

I want to copy an image into clipboard.
Kindly look below code. And suggest what is wrong with that.

Bitmap bmp = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.White, 0, 0, Width, Height);
PictureBox pb = new PictureBox();
pb.Image = bmp;
Clipboard.SetDataObject(pb);


Regards,
Asan
Posted
Updated 23-Nov-10 19:00pm
v2
Comments
Abhinav S 24-Nov-10 0:59am    
What is the problem? Are you getting an error?
JF2015 24-Nov-10 1:00am    
Edited for spelling.
Mohamed Asane 24-Nov-10 1:09am    
Thanks u both guys it's working now.
JF20157 and Abinav

Can you any one of guys please tell how to rotate an orignial image(ie. displaying horizontally) vertically.


Regards,
Asan
JF2015 24-Nov-10 1:19am    
For rotating: Have you checked this page?
http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate

1 solution

You are not copying the bitmap to the clipboard but the PictureBox. Try this code.
Bitmap bmp = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.White, 0, 0, Width, Height);
PictureBox pb = new PictureBox();
pb.Image = bmp;
Clipboard.SetDataObject(bmp);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900