J
JezB
I've implemented a drag & drop operation which allows an image (or a file
containing an image) to be dropped onto a custom control. This works fine on
dragging an image file already on my hard drive, but on dragging an Image
from any web page in a web browser, I'm getting an "Out of memory" exception
thrown, but there appears to be plenty of memory left. Why could this be
happening ?
NB. On dragging a web image, files[0] contains a reference to the image in
my web cache (in short directory format), for example:
"C:\\DOCUME~1\\JEREMYB\\LOCALS~1\\TEMP\\DisplayBannerImage.gif"
Could this be why ? If so how CAN I implement dragging an image from a web
browser ?
Here's the relevant sections of code:
public Form1()
{
InitializeComponent();
AlbumControl ac = new AlbumControl(p, atype, AutoLookup, cwidth /*,
false*/);
ac.AllowDrop = true;
ac.DragDrop += new DragEventHandler(ac_DragDrop);
ac.DragEnter += new DragEventHandler(ac_DragEnter);
}
private void ac_DragDrop(object sender, DragEventArgs e)
{
Image droppedImage = null;
// Handle FileDrop data.
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Assign the file names to a string array, in
// case the user has selected multiple files.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
try
{
// Assign the first image to the picture variable.
droppedImage = Image.FromFile(files[0]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
AlbumControl ac = (AlbumControl)sender;
if (droppedImage != null)
{
// DO SOMETHING WITH IMAGE !!
ac.MainImage = droppedImage;
}
// Force the control to be redrawn with the image.
ac.Invalidate();
}
private void ac_DragEnter(object sender, DragEventArgs e)
{
// If the data is a file or a bitmap, display the copy cursor.
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
containing an image) to be dropped onto a custom control. This works fine on
dragging an image file already on my hard drive, but on dragging an Image
from any web page in a web browser, I'm getting an "Out of memory" exception
thrown, but there appears to be plenty of memory left. Why could this be
happening ?
NB. On dragging a web image, files[0] contains a reference to the image in
my web cache (in short directory format), for example:
"C:\\DOCUME~1\\JEREMYB\\LOCALS~1\\TEMP\\DisplayBannerImage.gif"
Could this be why ? If so how CAN I implement dragging an image from a web
browser ?
Here's the relevant sections of code:
public Form1()
{
InitializeComponent();
AlbumControl ac = new AlbumControl(p, atype, AutoLookup, cwidth /*,
false*/);
ac.AllowDrop = true;
ac.DragDrop += new DragEventHandler(ac_DragDrop);
ac.DragEnter += new DragEventHandler(ac_DragEnter);
}
private void ac_DragDrop(object sender, DragEventArgs e)
{
Image droppedImage = null;
// Handle FileDrop data.
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Assign the file names to a string array, in
// case the user has selected multiple files.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
try
{
// Assign the first image to the picture variable.
droppedImage = Image.FromFile(files[0]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
AlbumControl ac = (AlbumControl)sender;
if (droppedImage != null)
{
// DO SOMETHING WITH IMAGE !!
ac.MainImage = droppedImage;
}
// Force the control to be redrawn with the image.
ac.Invalidate();
}
private void ac_DragEnter(object sender, DragEventArgs e)
{
// If the data is a file or a bitmap, display the copy cursor.
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}