Page 1 of 1

Use default icons on my own ribbonBar...

Posted: Mon Jun 19, 2017 8:20 am
by lidds
I want to use the default PDF-XChange icons on my own buttons on my application ribbonBar. I have come across the following post https://www.pdf-xchange.com/forum3 ... ns#p101826 however I don't understand how I can get the icon image returned. For example I would like to use your default annotation line icon on a button, which obviously means I need to return the icon as a bitmp or similar so I can add it to my button property.

Thanks

Simon

Re: Use default icons on my own ribbonBar...

Posted: Mon Jun 19, 2017 12:46 pm
by Sasha - Tracker Dev Team
Hello Simon,

Here's the way to do it:

Code: Select all

private void iconToBitmapToolStripMenuItem_Click(object sender, EventArgs e)
{
	IUIX_Cmd cmd = uiInst.CmdManager.Cmds.Find("cmd.save");
	IUIX_ImageData iData = null;
	tagRECT rc;
	cmd.Icon.GetItem(0, out iData, out rc);
	Bitmap image = new Bitmap(rc.right - rc.left, rc.bottom - rc.top);
	Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
	System.Drawing.Imaging.BitmapData bmpData = image.LockBits(rect, ImageLockMode.ReadWrite, image.PixelFormat);
	IntPtr outPtr = bmpData.Scan0;
	byte[] rgbValues = new byte[bmpData.Stride];
	uint nScan0 = (uint)(iData.Scan0 + iData.Stride * rc.top + rc.left * 4);
	IntPtr ptr = new IntPtr(nScan0);
	for (uint y = 0; y < (rc.bottom - rc.top); y++)
	{
		System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, (rc.right - rc.left) * 4);
		ptr = IntPtr.Add(ptr, iData.Stride);
		System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, outPtr, (rc.right - rc.left) * 4);
		outPtr = IntPtr.Add(outPtr, bmpData.Stride);
	}
	image.UnlockBits(bmpData);
	image.Save("D:\\TestFile.bmp");
}
Cheers,
Alex