Forum Discussion
7 Replies
Sort By
- aqAntSmartBear Alumni (Retired)
Hello Russell,
You can perform the conversion with Windows Clipboard. For example:
function Test()
{
var image = dotNET.System_Drawing.Bitmap.zctor("C:\\image.bmp");
image = dotNET.System_Windows_Interop.Imaging.CreateBitmapSourceFromHBitmap(
image.GetHbitmap(),
dotNET.System.IntPtr.Zero,
dotNET.System_Windows.Int32Rect.Empty,
dotNET.System_Windows_Media_Imaging.BitmapSizeOptions.FromEmptyOptions()
);
dotNET.System_Windows.Clipboard.SetImage(image);
var picture = Sys.Clipboard;
Log.Picture(picture);
} - rminnichContributorI am using TC 8.5 and have availability to 8.7. I do not see the dotNET.System_Windows* and dotNet.System_Drawing asseblies on my system. I do see other dotNet assemblies.
- aqAntSmartBear Alumni (Retired)
Hello Russell,
The sample was created in TestComplete 9, but it works fine in TestComplete 8, too.
In both cases, you need to configure your project's CLR Bridge settings in the following way:
- set the Preferred architecture of the assembly hosting process setting to 32-bit;
- set the Preferred apartment model of the calling thread setting to Single-threaded apartment;
- add the PresentationCore.dll, System.Drawing.dll and WindowsBase.dll assemblies from the GAC.
- andrew-6i6i6New Contributorhow make change in loaded image by dotNET? for example drawRectangle....
- aqAntSmartBear Alumni (Retired)
Hi Andrew,
Use the .NET Graphics class that provides the method. For example:
function Test()
{
var image = dotNET.System_Drawing.Image.FromFile("C:\\image.bmp");
var image_graphics = dotNET.System_Drawing.Graphics.FromImage(image);
var black_pen = dotNET.System_Drawing.Pen.zctor(dotNET.System_Drawing.Color.Black);
image_graphics.DrawRectangle(black_pen, 0, 0, 10, 10);
image_graphics.DrawImage(image, dotNET.System_Drawing.Point.zctor(0, 0));
var image_bitmap = dotNET.System_Drawing.Bitmap.zctor_10(image);
var bitmap_source = dotNET.System_Windows_Interop.Imaging.CreateBitmapSourceFromHBitmap(
image_bitmap.GetHbitmap(),
dotNET.System.IntPtr.Zero,
dotNET.System_Windows.Int32Rect.Empty,
dotNET.System_Windows_Media_Imaging.BitmapSizeOptions.FromEmptyOptions()
);
dotNET.System_Windows.Clipboard.SetImage(bitmap_source);
var picture = Sys.Clipboard;
Log.Picture(picture);
}
- andrew-6i6i6New ContributorThank!
but one more thing
How can I insert screen shot into dotNET Graphics
like this
dotNET.System_Windows.Clipboard.SetImage(bitmap_source);
var picture = Sys.Clipboard;
Log.Picture(picture);
Log.Message("first img");
var sbitmap=dotNET.System_Windows.Clipboard.GetImage();
var img=dotNET.System_Drawing.Image.FromHBitmap(sbitmap);
I have problem with conversation from System.Windows.Interop.InteropBitmap - aqAntSmartBear Alumni (Retired)
Hi Andrew,
The conversion was discussed on Stack Overflow. Here is the working solution:
function Test()
{
var bitmap_source = dotNET.System_Windows.Clipboard.GetImage();
var mstream = dotNET.System_IO.MemoryStream.zctor();
var encoder = dotNET.System_Windows_Media_Imaging.BmpBitmapEncoder.zctor();
encoder.Frames.Add(
dotNET.System_Windows_Media_Imaging.BitmapFrame.Create_5(bitmap_source)
);
encoder.Save(mstream);
var image_bitmap = dotNET.System_Drawing.Bitmap.zctor_4(mstream);
var image_graphics = dotNET.System_Drawing.Graphics.FromImage(image_bitmap);
}
Related Content
- 4 years agoStrone22
- 11 years agojimpson
- 9 years agotwhitehouse
Recent Discussions
- 52 minutes agoSvetaG