|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
Re: Preserving transparency in windowsNever thought of that!
Have you tested it?
Are you suggesting to set the agg rendering buffer to Scan0 ?
Can you possibly extend your sample code a bit further?
Either way, many thanks !
I will try it and let you know. From: Pierre Arnaud [mailto:pierre.arnaud@...] Sent: Wed 6/24/2009 22:39 To: 'Anti-Grain Geometry' Subject: Re: [AGG] Preserving transparency in windows Well, if I get you right, what you want is paint with AGG into the System.Drawing.Bitmap object ? I'd not use the complicated Graphics/HDC/Compatible DC/etc. stuff, but simply use (in C# syntax) something like that :
Rectangle rect = new Rectangle(0, 0, gdiBMP.Width, gdiBMP.Height); BitmapData bmpData = gdiBMP.LockBits(rect, ImageLockMode.ReadWrite, gdiBMP.PixelFormat);
bmpData.Scan0 contains the pointer to the first scan line (i.e. use it directly with the AGG rendering buffer) and bmpData.Stride contains the width in bytes for a given line.
When you are finished filling the buffer with AGG, simply UnlockBits and you should be done.
Pierre
From: George Vlahakis [mailto:g.vlahakis@...]
Actually it’s a requirement to be able to send back to a .NET framework app the transparent bmp.
Here is the code I am testing on and I can't shake those outline dots ...
int width = 320; int height = 240; //Also tried adding System::Drawing::Imaging::PixelFormat::Format32bppPArgb System::Drawing::Bitmap^ gdiBMP = gcnew System::Drawing::Bitmap(width, height); System::Drawing::Graphics^ g = System::Drawing::Graphics::FromImage(gdiBMP); IntPtr hdcPtr = g->GetHdc(); HDC hdc = (HDC)hdcPtr.ToPointer();
[...] ------------------------------------------------------------------------------ _______________________________________________ Vector-agg-general mailing list Vector-agg-general@... https://lists.sourceforge.net/lists/listinfo/vector-agg-general |
|
|
Re: Preserving transparency in windowsOk!
Many many thanks to Pierre for on the spot and prompt reply!
After a littlebit of testing here's the code that actually produces a .NET png file :
int width = 320;
int height = 240; // Create the gdi+ bitmap Bitmap^ gdiBMP = gcnew Bitmap(width, height, PixelFormat::Format32bppPArgb); // Notice that the pixel format is 32 bit premultiplied to match pixf_type below. Couldn't get // this to work if both weren't pre multiplied BitmapData^ bmpData = gdiBMP->LockBits(System::Drawing::Rectangle(0,0,width,height),ImageLockMode::ReadWrite, PixelFormat::Format32bppPArgb); // Get pointer to bmp data buffer void* scan0 = bmpData->Scan0.ToPointer(); // AGG lowest level code. agg::rendering_buffer rbuf; // Use stride of your liking (negative/positive) rbuf.attach((unsigned char*) scan0, width, height, -bmpData->Stride); // Pixel format and basic primitives renderer typedef agg::pixfmt_bgra32_pre pixf_type; pixf_type pixf(rbuf); agg::renderer_base<pixf_type> renb(pixf); renb.clear(agg::rgba8_pre(0, 0, 0, 0)); // Scanline renderer for solid filling. agg::renderer_scanline_aa_solid<agg::renderer_base<pixf_type> > ren(renb); // Rasterizer & scanline agg::rasterizer_scanline_aa<> ras; agg::scanline_p8 sl; // Polygon (triangle) ras.move_to_d(20.7, 34.15); ras.line_to_d(398.23, 123.43); ras.line_to_d(165.45, 401.87); // Setting the attrribute (color) & Rendering ren.color(agg::rgba8_pre(255, 255, 255)); agg::render_scanlines(ras, sl, ren); // Simple now gdiBMP->UnlockBits(bmpData); gdiBMP->Save("test.png", ImageFormat::Png); From: Pierre Arnaud [mailto:pierre.arnaud@...] Sent: Wed 6/24/2009 22:39 To: 'Anti-Grain Geometry' Subject: Re: [AGG] Preserving transparency in windows Well, if I get you right, what you want is paint with AGG into the System.Drawing.Bitmap object ? I'd not use the complicated Graphics/HDC/Compatible DC/etc. stuff, but simply use (in C# syntax) something like that :
Rectangle rect = new Rectangle(0, 0, gdiBMP.Width, gdiBMP.Height); BitmapData bmpData = gdiBMP.LockBits(rect, ImageLockMode.ReadWrite, gdiBMP.PixelFormat);
bmpData.Scan0 contains the pointer to the first scan line (i.e. use it directly with the AGG rendering buffer) and bmpData.Stride contains the width in bytes for a given line.
When you are finished filling the buffer with AGG, simply UnlockBits and you should be done.
Pierre
From: George Vlahakis [mailto:g.vlahakis@...]
Actually it’s a requirement to be able to send back to a .NET framework app the transparent bmp.
Here is the code I am testing on and I can't shake those outline dots ...
int width = 320; int height = 240; //Also tried adding System::Drawing::Imaging::PixelFormat::Format32bppPArgb System::Drawing::Bitmap^ gdiBMP = gcnew System::Drawing::Bitmap(width, height); System::Drawing::Graphics^ g = System::Drawing::Graphics::FromImage(gdiBMP); IntPtr hdcPtr = g->GetHdc(); HDC hdc = (HDC)hdcPtr.ToPointer();
[...] ------------------------------------------------------------------------------ _______________________________________________ Vector-agg-general mailing list Vector-agg-general@... https://lists.sourceforge.net/lists/listinfo/vector-agg-general |
|
|
Re: Preserving transparency in windowsGreat, you managed to
get it to work. Yes, I am using this approach myself in Creative Docs .NET,
whenever I need to paint into a .NET managed bitmap. Thank you in the name
of the other .NET users who have not yet a working code for you complete sample
:-) From: George Vlahakis
[mailto:g.vlahakis@...] Ok! Many
many thanks to Pierre for on the spot and prompt reply! After
a littlebit of testing here's the code that actually produces a .NET png file : int
width = 320; ------------------------------------------------------------------------------ _______________________________________________ Vector-agg-general mailing list Vector-agg-general@... https://lists.sourceforge.net/lists/listinfo/vector-agg-general |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |