[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Error When Copying Bitmap From Clipboard

Ata

12/2/2004 9:41:00 AM

Hello,

When I paste data as DataFormats.Bitmap from an image stream to the
clipboard, and then retrieve the possible formats, the list contains
"System.Drawing.Bitmap" and "Bitmap". If I use DataFormats.Dib, the list
contains only "DeviceIndependentBitmap". I notice that the possible formats
when I copy an image from MSPaint to the clipboard include "Embed Source",
"Object Descriptor", "MetaFilePict", and "DeviceIndependentBitmap".

When I try to paste the Dib/Bitmap contents of the clipboard to a PowerPoint
slide, I get an error. However, the clipped content from MSPaint can be
pasted. I think this might be because of the supported/associated formats. Is
there any way to enhance the list of supported formats of clipboard content
so that it can be pasted successfully?

Thanks,
Ajay.

ERROR
*****
An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in WindowsApplication2.exe

Additional information: Shapes (unknown member) : Invalid request.
Clipboard is empty or contains data which may not be pasted here.

CODE
****
// Obtain an image stream in "results", which is Byte[]

MemoryStream MemStream = new MemoryStream(results);
DataObject d = new DataObject();
d.SetData(DataFormats.Bitmap, true, MemStream);
Clipboard.SetDataObject(d, true);

PowerPoint.Presentation ppt;
PowerPoint.Application pptApp;
PowerPoint.Slide slide;
pptApp = new PowerPoint.Application();
ppt = pptApp.Presentations.Add(MsoTriState.msoTriStateMixed);

slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank)
slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteDefault,MsoTriState.msoFalse,"",0,"",MsoTriState.msoFalse);
ppt.SaveAs("D:\\Ata\\test.ppt",
PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);
2 Answers

Landley

1/11/2005 11:39:00 PM

0

It sounds like the old clipboard already in use bug. You may need to do a
dirty work around, and do a number of retries before it is successful.

Please post you code.

L.

"Ata" <ajay.abraham@wipro.com> wrote in message
news:B3549BFF-663B-4D95-95B9-2AEEAF98D3FE@microsoft.com...
> Hello,
>
> When I paste data as DataFormats.Bitmap from an image stream to the
> clipboard, and then retrieve the possible formats, the list contains
> "System.Drawing.Bitmap" and "Bitmap". If I use DataFormats.Dib, the list
> contains only "DeviceIndependentBitmap". I notice that the possible
formats
> when I copy an image from MSPaint to the clipboard include "Embed Source",
> "Object Descriptor", "MetaFilePict", and "DeviceIndependentBitmap".
>
> When I try to paste the Dib/Bitmap contents of the clipboard to a
PowerPoint
> slide, I get an error. However, the clipped content from MSPaint can be
> pasted. I think this might be because of the supported/associated formats.
Is
> there any way to enhance the list of supported formats of clipboard
content
> so that it can be pasted successfully?
>
> Thanks,
> Ajay.
>
> ERROR
> *****
> An unhandled exception of type
'System.Runtime.InteropServices.COMException'
> occurred in WindowsApplication2.exe
>
> Additional information: Shapes (unknown member) : Invalid request.
> Clipboard is empty or contains data which may not be pasted here.
>
> CODE
> ****
> // Obtain an image stream in "results", which is Byte[]
>
> MemoryStream MemStream = new MemoryStream(results);
> DataObject d = new DataObject();
> d.SetData(DataFormats.Bitmap, true, MemStream);
> Clipboard.SetDataObject(d, true);
>
> PowerPoint.Presentation ppt;
> PowerPoint.Application pptApp;
> PowerPoint.Slide slide;
> pptApp = new PowerPoint.Application();
> ppt = pptApp.Presentations.Add(MsoTriState.msoTriStateMixed);
>
> slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);
>
slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteDefault,MsoTriSt
ate.msoFalse,"",0,"",MsoTriState.msoFalse);
> ppt.SaveAs("D:\\Ata\\test.ppt",
> PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);


Ata

1/14/2005 10:31:00 AM

0

Thank you for your response. I would like to mention that I have since solved
this problem by using a feature of Reporting Services so this is not critical
for me any more in terms of getting a solution. However, I am stil curious in
terms of your opinion as to why this didn't work so that similar blockers can
be overcome in the future. Please dedicated your time to this when you have
some to spare.

The code is as follows (as I haven't cleaned up the code, please ignore any
portions that we inserted for debugging purposes). Please note that, in order
to run this successfully, you would need to add a Web reference to the
Reporting Services Web service.

// Create an instance of the proxy class for the Reporting Service
// Web service, and then specify the access credentials.
rsProxy = new MyReport.ReportingService();
rsProxy.Credentials = CredentialCache.DefaultCredentials;

// Prepare arguments for calling WebMethod "Render".
string historyID = null;
string deviceInfo = null;
deviceInfo = "<DeviceInfo><OutputFormat>BMP</OutputFormat></DeviceInfo>";
string showHide = null;
MyReport.ParameterValue[] param = null;
MyReport.DataSourceCredentials[] credentials = null;
Byte[] results;
string encoding; //Encoding used by WebMethod
string mimeType;
MyReport.Warning[] warnings = null; //To collect warnings returned by
WebMethod
MyReport.ParameterValue[] reportHistoryParameters = null;
string[] streamIDs = null;

// Execute the report. In the absence of Reporting Services,
// I think (but I am not sure) that retrieving an image stream
// from an image file will serve for testing purposes.
results = rsProxy.Render("/ESTP Reports/PartnerUpdate", "IMAGE",
historyID, deviceInfo, param,
credentials, showHide, out encoding, out mimeType,
out reportHistoryParameters, out warnings, out streamIDs);

// Copy the stream to the clipboard.
MemoryStream MemStream = new MemoryStream(results);
DataObject d1 = new DataObject();
// I have tried changing the first parameter to the other
// possible options but all fail with some error or the other.
d1.SetData(DataFormats.Bitmap,true,MemStream);
Clipboard.SetDataObject(d1, true);

// PowerPoint automation.
PowerPoint.Presentation ppt;
PowerPoint.Application pptApp;
PowerPoint.Slide slide;
pptApp = new PowerPoint.Application();
ppt = pptApp.Presentations.Add(MsoTriState.msoTriStateMixed);
slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);

// I have tried changing the first parameter to the other
// possible options but all fail with some error or the other.
slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteBitmap,MsoTriState.msoFalse,"",0,"",MsoTriState.msoFalse);
ppt.SaveAs("D:\\Ata\\test.ppt",
PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);

Thanks once again for your help!

Regards,
Ajay.

"Landley" wrote:

> It sounds like the old clipboard already in use bug. You may need to do a
> dirty work around, and do a number of retries before it is successful.
>
> Please post you code.
>
> L.
>
> "Ata" <ajay.abraham@wipro.com> wrote in message
> news:B3549BFF-663B-4D95-95B9-2AEEAF98D3FE@microsoft.com...
> > Hello,
> >
> > When I paste data as DataFormats.Bitmap from an image stream to the
> > clipboard, and then retrieve the possible formats, the list contains
> > "System.Drawing.Bitmap" and "Bitmap". If I use DataFormats.Dib, the list
> > contains only "DeviceIndependentBitmap". I notice that the possible
> formats
> > when I copy an image from MSPaint to the clipboard include "Embed Source",
> > "Object Descriptor", "MetaFilePict", and "DeviceIndependentBitmap".
> >
> > When I try to paste the Dib/Bitmap contents of the clipboard to a
> PowerPoint
> > slide, I get an error. However, the clipped content from MSPaint can be
> > pasted. I think this might be because of the supported/associated formats.
> Is
> > there any way to enhance the list of supported formats of clipboard
> content
> > so that it can be pasted successfully?
> >
> > Thanks,
> > Ajay.
> >
> > ERROR
> > *****
> > An unhandled exception of type
> 'System.Runtime.InteropServices.COMException'
> > occurred in WindowsApplication2.exe
> >
> > Additional information: Shapes (unknown member) : Invalid request.
> > Clipboard is empty or contains data which may not be pasted here.
> >
> > CODE
> > ****
> > // Obtain an image stream in "results", which is Byte[]
> >
> > MemoryStream MemStream = new MemoryStream(results);
> > DataObject d = new DataObject();
> > d.SetData(DataFormats.Bitmap, true, MemStream);
> > Clipboard.SetDataObject(d, true);
> >
> > PowerPoint.Presentation ppt;
> > PowerPoint.Application pptApp;
> > PowerPoint.Slide slide;
> > pptApp = new PowerPoint.Application();
> > ppt = pptApp.Presentations.Add(MsoTriState.msoTriStateMixed);
> >
> > slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);
> >
> slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteDefault,MsoTriSt
> ate.msoFalse,"",0,"",MsoTriState.msoFalse);
> > ppt.SaveAs("D:\\Ata\\test.ppt",
> > PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);
>
>
>