It is not throwing Exception but I am expecting it will copy the clipped
image into a Clipboard, which it is not doing. I am really surprised.
This is such a simple issue to copy a portion of the image to clipboard and
I am not able to do.
I am really glad I have a friend who is helping me out.
This is an Image Control I am writing. This has a toolbar and few buttons.
All the buttons are working fine except the code for this "Copy" button.
Once the user zooms in to the portion of the image and when he clicks copy,
I want that zoomed portion of the image to be transfered to the clipboard.
Here is the code after the user clicks the button.
The ImageRect is a RectangleF object and I am manipulating its values as and
when the user zooms in or zooms out or pan. Then applying this ImageRect on
the original image so that the right portion of the image is drawn for the
user.
TheImage to draw is an Image Object, which has the original image.
The test image I am using has a dimension of 3592 x 2485. It is a .tif image
file.
private void toolBarIB_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
this.Current_ToolName = e.Button.Text ;
if (e.Button.Text == "FZoomIn")
{
float WidthFactor = ImageRect.Width / 5 ;
float HeightFactor = ImageRect.Height / 5 ;
ImageRect.X = ImageRect.X + WidthFactor ;
ImageRect.Y = ImageRect.Y + HeightFactor ;
ImageRect.Width = ImageRect.Width - (2 * WidthFactor) ;
ImageRect.Height = ImageRect.Height - (2 * HeightFactor) ;
this.Cursor = System.Windows.Forms.Cursors.Default ;
Invalidate() ;
}
else if (e.Button.Text == "FZoomOut")
{
float WidthFactor = ImageRect.Width / 5 ;
float HeightFactor = ImageRect.Height / 5 ;
ImageRect.X = ImageRect.X - WidthFactor ;
ImageRect.Y = ImageRect.Y - HeightFactor ;
ImageRect.Width = ImageRect.Width + (2 * WidthFactor) ;
ImageRect.Height = ImageRect.Height + (2 * HeightFactor) ;
this.Cursor = System.Windows.Forms.Cursors.Default ;
Invalidate() ;
}
else if (e.Button.Text == "Pan")
{
this.Cursor = new Cursor(this.GetType(), "HandCursor.cur");
}
else if (e.Button.Text == "FullExtent")
{
this.ImageRect = this.Initial_ImageRect ;
Invalidate() ;
}
else if (e.Button.Text == "ZoomIn")
{
this.Cursor = System.Windows.Forms.Cursors.Cross ;
}
else if (e.Button.Text == "ZoomOut")
{
this.Cursor = System.Windows.Forms.Cursors.Cross ;
}
else if (e.Button.Text == "Copy")
{
try
{
System.Drawing.Bitmap TheClippedBmp = new Bitmap((int)this.ImageRect.Width,
(int)this.ImageRect.Height);
Graphics Gra = Graphics.FromImage(TheClippedBmp);
Gra.DrawImageUnscaled(this.TheImagetoDraw, (int) ImageRect.X ,(int)
ImageRect.Y,(int) ImageRect.Width,(int) ImageRect.Height);
System.Windows.Forms.Clipboard.SetDataObject(TheClippedBmp) ;
Gra.Dispose() ;
TheClippedBmp.Dispose() ;
this.statusBarPanelIBMsg.Text = "Data copied successfully !" ;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message) ;
}
}
else if (e.Button.Text == "Measure")
{
this.Cursor = System.Windows.Forms.Cursors.Cross ;
}
}
Jonathan Schafer said:
See embedded comments below:
Jonathan Schafer
On Mon, 14 Jul 2003 23:49:48 -0700, "Anand Ganesh"
Hi ,
I am sorry if I am troubling you or may be I am having difficulty
understanding the code.
Here is your code and my understanding
System.Drawing.Bitmap bmp = new Bitmap(30, 30); [ Creates an
empty bmp of size 30 x 30 ]
Image