Manikandan wrote:Hi Charlie Young ,
I did the change what you said. No image is displayed and the width & size values shows as 0. why ?
Please help. it is urgent .
Regards,
Manikandan
I spent some time on this, learning a few things myself.
The
Size100thMM property is not available in all cases. I discovered this after trying the "Fit picture in margins" trick I posted in the other thread on different pictures.
The main item of interest using Size100thMM was in setting the original size, but in fitting to the margins only the ratio of height to width is important, and that pops up a division by 0 error, of course. In the case of the Size100thMM property being zeroes, I found that the Graphic.Size property, although MRI showed it to as non-zero, didn't work either. What worked for me was instead of using oGraph.Graphic.Size100thMM, was to back up and use oGraph.Bitmap, though I can't say this will work in all cases.
You can pick your own test image. What I find is if I get something from Google Images, if I do "Save Image As," the problem appears, but if I paste into a graphic editor and save from there, everything is OK.
Don't ask why and don't be shocked. The image I used for testing was the August 5, 1982 cover of
Rolling Stone, featuring
The Go-Go's in their underwear.
Since I actually share much of Villeroy's disdain for the Basic language, I tried this in c++, where the fit margins looks like
Code: Select all
Sequence < ::com::sun::star::beans::PropertyValue > args(2);
args[0].Name = OUString::createFromAscii("Hidden");
args[0].Value <<= sal_False;
args[1].Name = OUString::createFromAscii("MacroExecutionMode");
args[1].Value <<= (sal_Int16) 4;
//get an instance of the spreadsheet
Reference< XComponent > xcomponent = rComponentLoader->loadComponentFromURL(
OUString::createFromAscii("private:factory/swriter"),
OUString::createFromAscii("_blank"),
0,
args);
Reference< XTextDocument > rTextDoc (xcomponent, UNO_QUERY);
Reference< XText > oText = rTextDoc->getText();
Reference<XStyleFamiliesSupplier> xStyleFamilies(rTextDoc, UNO_QUERY);
Reference< XNameAccess > xNameAccess = xStyleFamilies->getStyleFamilies();
Reference< XNameContainer > xNameContainer(xNameAccess->getByName(OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyles"))), UNO_QUERY);
Reference< XNameAccess > xNameAccess_2(xNameContainer, UNO_QUERY);
Reference< XStyle > xStyle(xNameAccess_2->getByName(OUString(RTL_CONSTASCII_USTRINGPARAM("Standard"))), UNO_QUERY);
Reference< XPropertySet > xPropertySet(xStyle, UNO_QUERY);
Any aSize = xPropertySet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Size")));
Any lMargin = xPropertySet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("LeftMargin")));
Any rMargin = xPropertySet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("RightMargin")));
Size oSize;
aSize >>= oSize;
long leftMargin, rightMargin;
lMargin >>= leftMargin;
rMargin >>= rightMargin;
long PageWidth = oSize.Width - leftMargin - rightMargin;
oSize.Width = PageWidth;
char URL[2048];
char *sURL;
sURL = ConvertToURL(URL,"C:\\Documents and Settings\\Charlie\\My Documents\\gogocoverx.jpg");
Reference<XTextCursor> oCursor = oText->createTextCursor();
Reference<XMultiServiceFactory> docFactory(xcomponent, UNO_QUERY);
Reference<XInterface> GraphicObjectShape = docFactory->createInstance(OUString::createFromAscii("com.sun.star.drawing.GraphicObjectShape"));
Reference<XShape> oGraph(GraphicObjectShape, UNO_QUERY);
Reference< XPropertySet > gShapeProps(oGraph,UNO_QUERY);
Any a;
OUString aOU = OUString::createFromAscii(sURL);
a <<= aOU;
gShapeProps->setPropertyValue(OUString::createFromAscii("GraphicURL"),a);
gShapeProps->setPropertyValue(OUString::createFromAscii("VertOrient"),(Any) (sal_Int8) 1);
Reference<XTextRange> oCursorRange(oCursor, UNO_QUERY);
Reference<XTextContent> oGraphContent(oGraph, UNO_QUERY);
oText->insertTextContent(oCursorRange,oGraphContent,sal_False);
Reference< XGraphic > oGraphic( gShapeProps->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Graphic"))), UNO_QUERY );
Reference< XPropertySet > graphicShapeProps(oGraphic,UNO_QUERY);
aSize = graphicShapeProps->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Size100thMM")));
Size gSize;
aSize >>= gSize;
oSize.Height = PageWidth * gSize.Height/gSize.Width;
oGraph->setSize(oSize);
and a version of ConvertToURL (strfile is the actual filename, URL is just a char array passed for storage allocation).
Code: Select all
char *ConvertToURL(char *URL,char *strfile)
{
long i, j, l;
l = strlen(strfile);
strcpy_s(URL,2048,"file:///");
j = 8;
for(i = 0;i < l; i++)
{
if(strfile[i] == ' ') {
strcpy_s(&URL[j],2048,"%20");
j += 3;
}
else if(strfile[i] == '\\') {
URL[j] = '/';
j++;
}
else {
URL[j] = strfile[i];
j++;
}
}
URL[j] = '\0';
return URL;
}