[Mono-list] using gdi+ with gtk#
Miguel de Icaza
miguel@ximian.com
Thu, 27 May 2004 18:07:22 -0400
--=-YG1vOL3ryCg//wl/t3rU
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hello,
> Im making a little html renderer with gdi+
> (http://www.compona.com/xhtmlrender10.gif)
> Now I want to try to host this renderer in gtk#
> so I wonder if its possible to display a gdi+ image on a gtk#
> container?
Yes, it is possible.
We should get this into a library, but for now this will do it:
Compile like this:
mcs -r:System.Drawing -pkg:gtk-sharp DrawingSample.cs sysdraw.cs
Miguel
--=-YG1vOL3ryCg//wl/t3rU
Content-Disposition: attachment; filename=DrawingSample.cs
Content-Transfer-Encoding: base64
Content-Type: text/x-csharp; name=DrawingSample.cs; charset=iso-8859-1
Ly8NCi8vIFNhbXBsZSBwcm9ncmFtIGRlbW9zdHJhdGluZyB1c2luZyBDYWlybyB3aXRoIEd0ayMN
Ci8vDQp1c2luZyBHdGs7DQp1c2luZyBTeXN0ZW07DQp1c2luZyBTeXN0ZW0uRHJhd2luZzsNCg0K
Y2xhc3MgWCB7DQoJc3RhdGljIERyYXdpbmdBcmVhIGEsIGI7DQoJDQoJc3RhdGljIHZvaWQgTWFp
biAoKQ0KCXsNCgkJQXBwbGljYXRpb24uSW5pdCAoKTsNCgkJR3RrLldpbmRvdyB3ID0gbmV3IEd0
ay5XaW5kb3cgKCJIZWxsbyIpOw0KDQoJCWEgPSBuZXcgUHJldHR5R3JhcGhpYyAoKTsNCg0KI2lm
IGZhbHNlDQoJCWIgPSBuZXcgRHJhd2luZ0FyZWEgKCk7DQoJCWIuRXhwb3NlRXZlbnQgKz0gQ2ly
Y2xlc0V4cG9zZUhhbmRsZXI7DQoJCWIuU2l6ZUFsbG9jYXRlZCArPSBTaXplQWxsb2NhdGVkSGFu
ZGxlcjsNCiNlbmRpZg0KCQkNCgkJQm94IGJveCA9IG5ldyBIQm94ICh0cnVlLCAwKTsNCgkJYm94
LkFkZCAoYSk7DQoJCS8vYm94LkFkZCAo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A7IGogKz0gMzApDQoJCQkJCWcuRHJhd0xpbmUgKHAsIGksIDAsIDAs
IGopOw0KCQl9DQoJCXJldHVybiB0cnVlOw0KCX0NCn0NCg==
--=-YG1vOL3ryCg//wl/t3rU
Content-Disposition: attachment; filename=sysdraw.cs
Content-Transfer-Encoding: base64
Content-Type: text/x-csharp; name=sysdraw.cs; charset=iso-8859-1
dXNpbmcgU3lzdGVtOw0KdXNpbmcgU3lzdGVtLlJlZmxlY3Rpb247DQp1c2luZyBTeXN0ZW0uUnVu
dGltZS5JbnRlcm9wU2VydmljZXM7DQoNCm5hbWVzcGFjZSBHZGsgew0KCXB1YmxpYyBjbGFzcyBH
cmFwaGljcyB7DQoJCQ0KCQlbRGxsSW1wb3J0KCJsaWJnZGstd2luMzItMi4wLTAuZGxsIildDQoJ
CWludGVybmFsIHN0YXRpYyBleHRlcm4gSW50UHRyIGdka194MTFfZHJhd2FibGVfZ2V0X3hkaXNw
bGF5IChJbnRQdHIgcmF3KTsNCgkJDQoJCVtEbGxJbXBvcnQoImxpYmdkay13aW4zMi0yLjAtMC5k
bGwiKV0NCgkJaW50ZXJuYWwgc3RhdGljIGV4dGVybiBJbnRQdHIgZ2RrX3gxMV9kcmF3YWJsZV9n
ZXRfeGlkIChJbnRQdHIgcmF3KTsNCgkJDQoJCXB1YmxpYyBzdGF0aWMgU3lzdGVtLkRyYXdpbmcu
R3JhcGhpY3MgRnJvbURyYXdhYmxlIChHZGsuRHJhd2FibGUgZHJhd2FibGUpDQoJCXsNCgkJCUlu
dFB0ciB4X2RyYXdhYmxlOw0KCQkJaW50IHhfb2ZmID0gMCwgeV9vZmYgPSAwOw0KCQkJCQ0KCQkJ
DQoJCQlpZiAoZHJhd2FibGUgaXMgR2RrLldpbmRvdyl7DQoJCQkJKChHZGsuV2luZG93KSBkcmF3
YWJsZSkuR2V0SW50ZXJuYWxQYWludEluZm8ob3V0IGRyYXdhYmxlLCBvdXQgeF9vZmYsIG91dCB5
X29mZik7DQoJCQl9I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