本文整理汇总了C#中System.Windows.Forms.DataObject.SetImage方法的典型用法代码示例。如果您正苦于以下问题:C# DataObject.SetImage方法的具体用法?C# DataObject.SetImage怎么用?C# DataObject.SetImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataObject
的用法示例。
在下文中一共展示了DataObject.SetImage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: copyToClipBoard
public static void copyToClipBoard(Expr expr, Image image)
{
string[] s = new string[1];
s[0] = FileUtility.FullPath(expr);
DataObject dataObject = new DataObject();
dataObject.SetData(DataFormats.FileDrop, s);
dataObject.SetImage(image);
Clipboard.SetDataObject(dataObject);
}
示例2: TestImage
public void TestImage ()
{
DataObject d = new DataObject ();
Image i = new Bitmap (16, 16);
d.SetImage (i);
Assert.AreEqual (false, d.ContainsAudio (), "A1");
Assert.AreEqual (false, d.ContainsFileDropList (), "A2");
Assert.AreEqual (true, d.ContainsImage (), "A3");
Assert.AreEqual (false, d.ContainsText (), "A4");
Assert.AreEqual (false, d.ContainsText (TextDataFormat.CommaSeparatedValue), "A5");
Assert.AreSame (i, d.GetImage (), "A6");
}
示例3: SetClipboardData
//.........这里部分代码省略.........
dibStream.Write(tmpBmpStream.GetBuffer(), BITMAPFILEHEADER_LENGTH, (int)tmpBmpStream.Length - BITMAPFILEHEADER_LENGTH);
}
// Set the DIB to the clipboard DataObject
dataObject.SetData(DataFormats.Dib, true, dibStream);
}
} catch (Exception dibEx) {
LOG.Error("Error creating DIB for the Clipboard.", dibEx);
}
// CF_DibV5
try {
if (config.ClipboardFormats.Contains(ClipboardFormat.DIBV5)) {
// Create the stream for the clipboard
dibV5Stream = new MemoryStream();
// Create the BITMAPINFOHEADER
BITMAPINFOHEADER header = new BITMAPINFOHEADER(imageToSave.Width, imageToSave.Height, 32);
// Make sure we have BI_BITFIELDS, this seems to be normal for Format17?
header.biCompression = BI_COMPRESSION.BI_BITFIELDS;
// Create a byte[] to write
byte[] headerBytes = BinaryStructHelper.ToByteArray<BITMAPINFOHEADER>(header);
// Write the BITMAPINFOHEADER to the stream
dibV5Stream.Write(headerBytes, 0, headerBytes.Length);
// As we have specified BI_COMPRESSION.BI_BITFIELDS, the BitfieldColorMask needs to be added
BitfieldColorMask colorMask = new BitfieldColorMask();
// Make sure the values are set
colorMask.InitValues();
// Create the byte[] from the struct
byte[] colorMaskBytes = BinaryStructHelper.ToByteArray<BitfieldColorMask>(colorMask);
Array.Reverse(colorMaskBytes);
// Write to the stream
dibV5Stream.Write(colorMaskBytes, 0, colorMaskBytes.Length);
// Create the raw bytes for the pixels only
byte[] bitmapBytes = BitmapToByteArray((Bitmap)imageToSave);
// Write to the stream
dibV5Stream.Write(bitmapBytes, 0, bitmapBytes.Length);
// Set the DIBv5 to the clipboard DataObject
dataObject.SetData(FORMAT_17, true, dibV5Stream);
}
} catch (Exception dibEx) {
LOG.Error("Error creating DIB for the Clipboard.", dibEx);
}
// Set the HTML
if (config.ClipboardFormats.Contains(ClipboardFormat.HTML)) {
string tmpFile = ImageOutput.SaveToTmpFile(surface, new SurfaceOutputSettings(OutputFormat.png, 100, false), null);
string html = getHTMLString(surface, tmpFile);
dataObject.SetText(html, TextDataFormat.Html);
} else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) {
string html;
using (MemoryStream tmpPNGStream = new MemoryStream()) {
SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false);
// Do not allow to reduce the colors, some applications dislike 256 color images
// reported with bug #3594681
pngOutputSettings.DisableReduceColors = true;
// Check if we can use the previously used image
if (imageToSave.PixelFormat != PixelFormat.Format8bppIndexed) {
ImageOutput.SaveToStream(imageToSave, surface, tmpPNGStream, pngOutputSettings);
} else {
ImageOutput.SaveToStream(surface, tmpPNGStream, pngOutputSettings);
}
html = getHTMLDataURLString(surface, tmpPNGStream);
}
dataObject.SetText(html, TextDataFormat.Html);
}
} finally {
// we need to use the SetDataOject before the streams are closed otherwise the buffer will be gone!
// Check if Bitmap is wanted
if (config.ClipboardFormats.Contains(ClipboardFormat.BITMAP)) {
dataObject.SetImage(imageToSave);
// Place the DataObject to the clipboard
SetDataObject(dataObject, true);
} else {
// Place the DataObject to the clipboard
SetDataObject(dataObject, true);
}
if (pngStream != null) {
pngStream.Dispose();
pngStream = null;
}
if (dibStream != null) {
dibStream.Dispose();
dibStream = null;
}
if (dibV5Stream != null) {
dibV5Stream.Dispose();
dibV5Stream = null;
}
// cleanup if needed
if (disposeImage && imageToSave != null) {
imageToSave.Dispose();
}
}
}
示例4: DraggableIcon_ItemDrag
private void DraggableIcon_ItemDrag(object sender, ItemDragEventArgs e)
{
try
{
using (var tsf = new TemporarySaveFile(this))
{
DataObject obj = new DataObject();
if (DraggableIcon.Items[0].Text.StartsWith("text/"))
{
string data_ = new StreamReader(tsf.data).ReadToEnd();
obj.SetText(data_, DraggableIcon.Items[0].Text == "text/html" ? TextDataFormat.Html : TextDataFormat.UnicodeText);
}
else if (DraggableIcon.Items[0].Text.StartsWith("image/"))
{
var data_ = new Bitmap(tsf.data);
obj.SetImage(data_);
}
else
obj.SetData(tsf.data);
tsf.data.Close();
obj.SetData(DataFormats.FileDrop, true, new String[] { tsf.tempfilename });
disable_scrolling = true;
try
{
DraggableIcon.DoDragDrop(obj, DragDropEffects.All);
}
finally
{
disable_scrolling = false;
}
}
}
catch (Exception ex)
{
MessageBox.Show(this, "Error when dragging file: " + ex.ToString(), "Error from BEurtle", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例5: GetPict2Clip
//Bitmapをクリップボードに保存
public Boolean GetPict2Clip()
{
if (kinect.IsRunning==false)
{
StartKinect(kinect);
}
using (ColorImageFrame colorFrame=kinect.ColorStream.OpenNextFrame(100))
{
if (colorFrame == null)
{
return false;
}
byte[] colorPixel = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(colorPixel);
//ピクセルデータをビットマップに変換
Bitmap bitmap =
new Bitmap(kinect.ColorStream.FrameWidth,
kinect.ColorStream.FrameHeight,
PixelFormat.Format32bppRgb);
Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
BitmapData data = bitmap.LockBits(rect, ImageLockMode.WriteOnly,
PixelFormat.Format32bppRgb);
Marshal.Copy(colorPixel, 0, data.Scan0, colorPixel.Length);
bitmap.UnlockBits(data);
//クリップボードに保存
DataObject dataobj = new DataObject();
dataobj.SetImage(bitmap);
Clipboard.SetDataObject(dataobj, true);
return true;
}
}
示例6: doCopy
private DataObject doCopy()
{
DataObject obj = new DataObject();
obj.SetText(charEditor.CurrentChar.ToDB());
obj.SetImage(charEditor.CurrentChar.ToBitmap());
obj.SetData(charEditor.CurrentChar);
return obj;
}
示例7: CopySelection
public void CopySelection()
{
Clipboard.Clear();
if (SelectionCount == 0)
return;
DataObject cdo = new DataObject();
int minX = 0;
int minY = 0;
int maxX = 0;
int maxY = 0;
string[] internalData = new string[SelectionCount + 1];
minX = int.MaxValue;
minY = int.MaxValue;
foreach (object v_loopVariable in selectedObjects) {
v = v_loopVariable;
RECT r = v.GetOuterBounds();
minX = Math.Min(minX, r.Left);
minY = Math.Min(minY, r.Top);
maxX = Math.Max(maxX, r.Right);
maxY = Math.Max(maxY, r.Bottom);
}
Point minPoint = default(Point);
Bitmap bmp = new Bitmap(maxX - minX, maxY - minY, Imaging.PixelFormat.Format32bppPArgb);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
g.TranslateTransform(-minX, -minY);
for (i = 0; i <= SelectionCount - 1; i++) {
var _with1 = selectedObjects[i];
_with1.isSelected = false;
_with1.DrawObject(g);
_with1.isSelected = true;
internalData[i] = _with1.ToHtml();
}
g.Dispose();
cdo.SetData("Bitmap", true, bmp.Clone);
cdo.SetData("ScreenGrabCollageItemList", false, internalData);
if (SelectionCount == 1) {
switch (GetSelectionType()) {
case "VTextbox":
cdo.SetText(((VTextbox)GetFirstSelectedObject()).Text);
break;
case "VImage":
cdo.SetImage(((VImage)GetFirstSelectedObject()).img);
break;
}
}
Clipboard.SetDataObject(cdo, true);
}