473,804 Members | 3,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return a Bitmap as IPicture

Hi,
I am writing a COM class in c# which needs to implement an interface which
one of its methods declared in the following way:
public stdole.IPicture GetBitmap()
{
}

I have a bitmap (MyBitmap.bmp) in my c# application and I want to load it,
and return it as a return value of the method GetBitmap.
I created a System.Drawing. Bitmap object and load it with MyBitmap.bmp file.
Now, I tried to convert my Bitmap object to stdole.IPicture , but I dont know
how to do it.

Can someone please help (or suggest a different approach) ?

thanks,
Yoav.
Jul 12 '06 #1
4 8085
Hi Yoavo,

System.Drawing. Bitmap does not implement the OLE IPicture interface. You'll
have to create your own implementation of that interface to wrap the Bitmap
object.

Actually, just on a hunch I searched for IPicture in the VS.NET 2005 object
browser and I discovered the following method:

System.Windows. Forms.AxHost.Ge tIPictureFromPi cture(System.Dr awing.Image)

Take a look at some of the other AxHost methods that deal with IPicture as
well. They may come in handy.

- Dave Sexton

"Yoavo" <yo**@cimatron. co.ilwrote in message
news:O%******** ********@TK2MSF TNGP03.phx.gbl. ..
Hi,
I am writing a COM class in c# which needs to implement an interface which
one of its methods declared in the following way:
public stdole.IPicture GetBitmap()
{
}

I have a bitmap (MyBitmap.bmp) in my c# application and I want to load it,
and return it as a return value of the method GetBitmap.
I created a System.Drawing. Bitmap object and load it with MyBitmap.bmp
file.
Now, I tried to convert my Bitmap object to stdole.IPicture , but I dont
know how to do it.

Can someone please help (or suggest a different approach) ?

thanks,
Yoav.


Jul 12 '06 #2
Unfortunately, this won't work. It is protected.

Instead, set a reference to Microsoft.Visua lBasic.Compatab ility, and
call either the static ImageToIPicture ir ImageToIPicture Disp methods on the
Support class in the Microsoft.Visua lBasic.Compatab ility.VB6 namespace.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Hi Yoavo,

System.Drawing. Bitmap does not implement the OLE IPicture interface.
You'll have to create your own implementation of that interface to wrap
the Bitmap object.

Actually, just on a hunch I searched for IPicture in the VS.NET 2005
object browser and I discovered the following method:

System.Windows. Forms.AxHost.Ge tIPictureFromPi cture(System.Dr awing.Image)

Take a look at some of the other AxHost methods that deal with IPicture as
well. They may come in handy.

- Dave Sexton

"Yoavo" <yo**@cimatron. co.ilwrote in message
news:O%******** ********@TK2MSF TNGP03.phx.gbl. ..
>Hi,
I am writing a COM class in c# which needs to implement an interface
which one of its methods declared in the following way:
public stdole.IPicture GetBitmap()
{
}

I have a bitmap (MyBitmap.bmp) in my c# application and I want to load
it, and return it as a return value of the method GetBitmap.
I created a System.Drawing. Bitmap object and load it with MyBitmap.bmp
file.
Now, I tried to convert my Bitmap object to stdole.IPicture , but I dont
know how to do it.

Can someone please help (or suggest a different approach) ?

thanks,
Yoav.



Jul 13 '06 #3
Hi Nicholas,
I tried to follow your instructions but I cant create
"Microsoft.Visu alBasic.Compata bility":
The only member of "Microsoft.Visu alBasic" is
"Microsoft.Visu alBasic.VBCodeP rovider"...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Unfortunately, this won't work. It is protected.

Instead, set a reference to Microsoft.Visua lBasic.Compatab ility, and
call either the static ImageToIPicture ir ImageToIPicture Disp methods on
the Support class in the Microsoft.Visua lBasic.Compatab ility.VB6
namespace.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>Hi Yoavo,

System.Drawing .Bitmap does not implement the OLE IPicture interface.
You'll have to create your own implementation of that interface to wrap
the Bitmap object.

Actually, just on a hunch I searched for IPicture in the VS.NET 2005
object browser and I discovered the following method:

System.Windows .Forms.AxHost.G etIPictureFromP icture(System.D rawing.Image)

Take a look at some of the other AxHost methods that deal with IPicture
as well. They may come in handy.

- Dave Sexton

"Yoavo" <yo**@cimatron. co.ilwrote in message
news:O%******* *********@TK2MS FTNGP03.phx.gbl ...
>>Hi,
I am writing a COM class in c# which needs to implement an interface
which one of its methods declared in the following way:
public stdole.IPicture GetBitmap()
{
}

I have a bitmap (MyBitmap.bmp) in my c# application and I want to load
it, and return it as a return value of the method GetBitmap.
I created a System.Drawing. Bitmap object and load it with MyBitmap.bmp
file.
Now, I tried to convert my Bitmap object to stdole.IPicture , but I dont
know how to do it.

Can someone please help (or suggest a different approach) ?

thanks,
Yoav.




Jul 13 '06 #4
Hi Yoavo,

Nicholas is correct, the method is protected static however it's documented
on MSDN so I don't see why you can't use it. If his VB assembly suggestion
doesn't work for you here is some code that will wrap the
AxHost.GetIPict ureFromPicture method for you, keeping the actual
implementation private since it's a bit ugly. Also, keep in mind that you
don't get intellisense for the call to "AxHost.GetIPic tureFromPicture "
because it's marked with EditorBrowsable (false), but I tested the code and
it compiles and executes just fine:

public static class ImageUtilities
{
public static object ConvertToIPictu re(Image image)
{
return ImageOLEConvert er.Instance.Con vertToIPicture( image);
}

private class ImageOLEConvert er : AxHost
{
public static readonly ImageOLEConvert er Instance = new
ImageOLEConvert er();

private ImageOLEConvert er()
: base(Guid.Empty .ToString())
{
}

public object ConvertToIPictu re(Image image)
{
return AxHost.GetIPict ureFromPicture( image);
}
}
}

In your code, just call ImageUtilities. ConvertToIPictu re(myImage).

HTH

"Yoavo" <yo**@cimatron. co.ilwrote in message
news:%2******** **********@TK2M SFTNGP05.phx.gb l...
Hi Nicholas,
I tried to follow your instructions but I cant create
"Microsoft.Visu alBasic.Compata bility":
The only member of "Microsoft.Visu alBasic" is
"Microsoft.Visu alBasic.VBCodeP rovider"...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote
in message news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
> Unfortunately, this won't work. It is protected.

Instead, set a reference to Microsoft.Visua lBasic.Compatab ility, and
call either the static ImageToIPicture ir ImageToIPicture Disp methods on
the Support class in the Microsoft.Visua lBasic.Compatab ility.VB6
namespace.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2******* *********@TK2MS FTNGP04.phx.gbl ...
>>Hi Yoavo,

System.Drawin g.Bitmap does not implement the OLE IPicture interface.
You'll have to create your own implementation of that interface to wrap
the Bitmap object.

Actually, just on a hunch I searched for IPicture in the VS.NET 2005
object browser and I discovered the following method:

System.Window s.Forms.AxHost. GetIPictureFrom Picture(System. Drawing.Image)

Take a look at some of the other AxHost methods that deal with IPicture
as well. They may come in handy.

- Dave Sexton

"Yoavo" <yo**@cimatron. co.ilwrote in message
news:O%****** **********@TK2M SFTNGP03.phx.gb l...
Hi,
I am writing a COM class in c# which needs to implement an interface
which one of its methods declared in the following way:
public stdole.IPicture GetBitmap()
{
}

I have a bitmap (MyBitmap.bmp) in my c# application and I want to load
it, and return it as a return value of the method GetBitmap.
I created a System.Drawing. Bitmap object and load it with MyBitmap.bmp
file.
Now, I tried to convert my Bitmap object to stdole.IPicture , but I dont
know how to do it.

Can someone please help (or suggest a different approach) ?

thanks,
Yoav.




Jul 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9996
by: Kent | last post by:
Hi! I am working with an obscure graphics library in school as a university C++ programming project. The graphics library has a class kalled Bitmap wich you use to draw graphics (you can "stamp it down" on the screen, double buffering and such is all within the lib). This is how it works now (i think its a bad design): In a class i created to represent "monsters" in a game i have the following
2
3031
by: Sharon | last post by:
I encountered a strange behavior when doing ‘new Bitmap’: The following code works fine and the given bitmap file is shown on the PictureBox (the m_DrawArea) in the correct bitmap sizes: private Graphics m_gMapImg; private Bitmap m_backroundImage; private Bitmap MapImg; private PictureBox m_DrawArea;
8
3333
by: Nathan Sokalski | last post by:
I am trying to write code to rotate a graphic that I have. Here is the code I am currently using: Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.RotateTransform(90) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
4
1809
by: Mark S. | last post by:
Hello, On a high volume page we have the following JavaScript: img = new Image() img.src = 'http://myserver.com/count.aspx?x=1'; and it works fine, but now we've added: img.onload = myImgLoaded and it fails on IE and FF. The reason being it's not returning a proper
12
3363
by: active | last post by:
I've been looking on the Internet for a way to convert a DIB to a Bitmap without success. Now I'm wondering if that is the approach I should be taking. All I want to do is display the DIB or draw it into a Bitmap. Is there a graphics method that can help?
8
4326
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the FromImage call will fail for indexed bitmaps.
2
2608
by: Peter Oliphant | last post by:
I want to create a new Bitmap which is a portion of an existing Bitmap. For example, if I have a Bitmap that is 100x100 in size I might want to create a new Bitmap that is equivalent to the one located at (x,y)=(10,20) (upper-left hand corner) and is 50x50 in size of the source Bitmap. A sub-Bitmap if you will, sort of the equivalent to sub-strings for a source string. I don't think this works, but something like: Bitmap^ src_bm = ...
6
7269
by: herzog | last post by:
Hi, I am using C# to a draw a graphic on a memory bitmap. I then extract the color information of every pixel of the bitmap. I do this with Bitmap.GetPixel(). The trouble I'm having is that I need Bitmap.GetPixel() to always return pure RGB values -- ones that always have an alpha value of 255. This is because I need to reproduce the graphic in a different environment that does not have alpha values. I realize I can get...
0
925
by: btuttle | last post by:
Hi all- I have an object that contains an IPictureDisp object and I would like to read it out and write it to disk. Presently, I am looking at casting it to an IPicture object and using the SaveAsFile method to achieve this. However, the IPicture interface is pretty new to me and much more complex (at least it seems so to me) than most of the items I usually use. So far I have not been able to successfully get the picture into a stream that I...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.