Hi,
I've now got an image displaying in my drawing, but it isn't scaleing correctly.
With this code I'm trying to display an image that is 50 units by 50 units.
Adesk::Boolean isPerspective = pVd->viewport().isPerspective(); AcGePoint3d originPos(0.0, 0.0, 0.0); AcGePoint2d scaleUnits; pVd->viewport().getNumPixelsInUnitSquare(originPos, scaleUnits, isPerspective != 0); long xWidth = (long)ceil(50 * scaleUnits.x); long yWidth = (long)ceil(50 * scaleUnits.y); if (xWidth > 2048 || yWidth > 2048) { if (xWidth >= yWidth) { yWidth = (long)(yWidth * (double)(2048.0 / xWidth)); xWidth = 2048; } else { xWidth = (long)(xWidth * (double)(2048.0 / yWidth)); yWidth = 2048; } } AcGiPixelBGRA32 *colorBlock = new AcGiPixelBGRA32[xWidth * yWidth]; for (int i = 0; i < yWidth; i++) { for (int j = 0; j < xWidth; j++) { colorBlock[(i*xWidth)+j].setRGBA(0,255,0,255); } } AcGiImageBGRA32 imageSource(xWidth, yWidth, colorBlock); double xScale = xWidth / scaleUnits.x; double yScale = yWidth / scaleUnits.y; AcGeVector3d u(xScale, 0.0, 0.0); AcGeVector3d v(0.0, yScale, 0.0); pVd->geometry().image(imageSource, originPos, u, v,AcGiGeometry::kTransparency8Bit);
When you zoom in close and redraw the image will shrink. Zoom out and the image displays correctly. When debugging the shrinking problem occurs when my xScale value is greater then scaleUnits.x value.
Another way to ask the question is; If I have a 2048x2048 image where each pixel is .0244 meters, what does the magnitude need to be so it will display at 50mx50m?
Thanks
Hi Darcy,
The u and v vectors that are inputs to "AcGiViewportGeometry::image" method are the width and height of the image to be drawn in drawing units.
So, if you have an image of 2048 x 2048 pixels size, and want it to be drawn in a 50 x 50 drawing units, you simply need to use u = AcGeVector3d::kXAxis * 50 and v = AcGeVector3d::kYAxis * 50 as the inputs to the image method.
I am not sure why you would need to use the values from the "getNumPixelsInUnitSquare", since that will be needed if you need to know the conversion factor in drawing units for each pixel.
If this does not help, please provide a reproducible sample project to demontrate the behavior.
Regards,
Balaji