I am trying to render the plugins to an in-memory bitmap instead of a control. I want to render these into my own UI system. However this does only work with WMP and Sonique plugins but not with Bassbox, which is very sad since Bassbox effects are very nice!
I modified the C# sample where I assign the in-memory bitmaps to the Image property of the PictureBoxes. So you can reproduce the problem easily. Please modify the Form1.cs as follows:
Graphics graphics1; // these are needed as additional members of frmMain...
Graphics graphics2;
Graphics graphics3;
private void frmMain_Load(object sender, EventArgs e)
{
int width = 192;
int height = 192;
int bpp = 24;
int stride = width * bpp + 7 / 8;
int numBytes = height * stride;
System.Drawing.Imaging.PixelFormat format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
// create in-memory bitmaps
Image image1 = new Bitmap(width, height, stride, format, Marshal.AllocCoTaskMem(numBytes));
Image image2 = new Bitmap(width, height, stride, format, Marshal.AllocCoTaskMem(numBytes));
Image image3 = new Bitmap(width, height, stride, format, Marshal.AllocCoTaskMem(numBytes));
// create graphics object from bitmaps
graphics1 = Graphics.FromImage(image1);
graphics2 = Graphics.FromImage(image2);
graphics3 = Graphics.FromImage(image3);
// assign bitmaps to PictureBox
m_oVisPanel.Image = image1;
m_oVisPanel2.Image = image2;
m_oVisPanel3.Image = image3;
// not needed, we use our own hdc in the timer method
//hVisDC = m_oVisPanel.CreateGraphics().GetHdc();
//hVisDC2 = m_oVisPanel2.CreateGraphics().GetHdc();
//hVisDC3 = m_oVisPanel3.CreateGraphics().GetHdc();
(... continue from here normally with BASS_Init as in sample!)
}
private void timer1_Tick(object sender, EventArgs e)
{
// get hdc for in-memory bitmaps (needs to be done every render pass)
hVisDC = graphics1.GetHdc();
hVisDC2 = graphics2.GetHdc();
hVisDC3 = graphics3.GetHdc();
// render to bitmaps
bool success = false;
if (hSFX != -1)
success = BASS_SFX_PluginRender(hSFX, hStream, hVisDC);
if (hSFX2 != -1)
success = BASS_SFX_PluginRender(hSFX2, hStream, hVisDC2);
if (hSFX3 != -1)
success = BASS_SFX_PluginRender(hSFX3, hStream, hVisDC3);
// release hdc
graphics1.ReleaseHdc();
graphics2.ReleaseHdc();
graphics3.ReleaseHdc();
// invalidate picture boxes to update the UI
m_oVisPanel.Invalidate();
m_oVisPanel2.Invalidate();
m_oVisPanel3.Invalidate();
}
It would be great if you could look into this issue. The bitmap dc should behave just like any other dc. I don't know if you are doing something fancy with them in the Bassbox adapter code, but none of the Bassbox plugins work with this code.
Please note that currently all plugins except for Sonique return false on the render call, even with the normal sample code where everything works great. Seems like a bug to me, but it has nothing to do with my problem.