Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
mobiledeveloper
Posts: 78
Registered: ‎04-05-2010
My Device: Storm

Regarding conversion and panning of SVG

Hi friends,

 

I am successfully able to display SVG image which comes with blackberry samples. But how can I convert the SVG image which is with me to blackberry accepable SVG format. I read the posts but they mention only for theme.

 

One more thing I want to know can I know how to move SVG image displayed on screen so that one can see only a part and when drag down then other parts and can also zoom in.

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Regarding conversion and panning of SVG

To convert a SVG to the BlackBerry specific version (known as PME... I think), you would have to use the Plazmic Content Builder. I believe it comes with the Theme Builder. If you have more questions it might be best to ask in http://supportforums.blackberry.com/t5/BlackBerry-Themes-Animated/bd-p/plazmic_cdk.

 

But that introduces an issue that I can't help you with, I don't know how you would programatically translate/rotate/scale a PME. If you leave it as SVG you can get the SVG Document by calling SVGImage.getDocument(). Get one of the child nodes (can't remember which) and it will be the root SVGSVGElement. From there you can get/set the scale, rotation, and translation of the SVG.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Regular Contributor
mobiledeveloper
Posts: 78
Registered: ‎04-05-2010
My Device: Storm

Re: Regarding conversion and panning of SVG

Thanks for guidance. Can you please provide more information on panning and zoom, because if I am doing it in logical way sometimes complete picture got vanished from screen and sometime appears. If you can provide any link for panning and zoom, I shall be thankful to you.

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Regarding conversion and panning of SVG

Sorry I couldn't find the code I was looking for at the time.

 

Code:

try
{
	ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes("UTF-8"));
	
	ScalableGraphics sg = ScalableGraphics.createInstance();
	sg.bindTarget(graphics);
	sg.setRenderingQuality(ScalableGraphics.RENDERING_QUALITY_HIGH);
	
	ScalableImage img = ScalableImage.createImage(bis, new ExternalResourceHandler()
	{
		public void requestResource(ScalableImage image, String URI)
		{
			System.out.println("Should not happen");
		}
	});
	img.setViewportHeight(100);
	img.setViewportWidth(100);
	SVGImage svgImg = (SVGImage)img;
	Document doc = svgImg.getDocument();
	SVGSVGElement root = (SVGSVGElement)doc.getDocumentElement();
	root.setCurrentScale(10f);
	
	sg.render(50, 50, img);
	
	sg.releaseTarget();
	
	bis.close();
}
catch(Exception e)
{
}

 

I had written he code for speed tests (what is faster to load; File reading, direct byte array, String, resource, etc.). You can change the scale, rotation, and translation using the setCurrentScale/Rotation and getCurrentTranslate functions.

 

"str" is a String that contained the SVG I was using, it made a capital letter 'G'.

 

SVG:

String str = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?><svg xmlns:svg=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"6.62109375\" height=\"7.40234375\" id=\"svg2\">" + 
"<defs id=\"defs4\" /><g id=\"layer1\">" + 
"<path d=\"M 3.5888671875,4.47265625 L 3.5888671875,3.6328125 6.62109375,3.6279296875 6.62109375,6.2841796875 C 6.15559864044189,6.6552734375 5.67545557022095,6.93440759181976 5.1806640625,7.12158203125 4.68587207794189,7.30875650420785 4.17805957794189,7.40234375 3.6572265625,7.40234375 2.95410132408142,7.40234375 2.31526660919189,7.25179035961628 1.74072265625,6.95068359375 1.16617834568024,6.64957684278488 0.732421875,6.21419262886047 0.439453125,5.64453125 0.146484375,5.07486987113953 0,4.4384765625 0,3.7353515625 0,3.03873729705811 0.145670533180237,2.38850927352905 0.43701171875,1.78466796875 0.728352785110474,1.18082714080811 1.1474609375,0.732422351837158 1.6943359375,0.439453125 2.24121069908142,0.146484851837158 2.87109351158142,4.76837158203125E-07 3.583984375,0 4.1015625,4.76837158203125E-07 4.56949853897095,0.0838222503662109 4.98779296875,0.25146484375 5.40608692169189,0.419108390808105 5.73404932022095,0.652669429779053 5.9716796875,0.9521484375 6.20930957794189,1.25162792205811 6.38997364044189,1.64225292205811 6.513671875,2.1240234375 L 5.6591796875,2.3583984375 C 5.5517578125,1.99381542205811 5.41829395294189,1.70735692977905 5.2587890625,1.4990234375 5.09928369522095,1.29069042205811 4.87141895294189,1.12386131286621 4.5751953125,0.99853515625 4.27897119522095,0.873209953308105 3.9501953125,0.810546875 3.5888671875,0.810546875 3.15592432022095,0.810546875 2.78157520294189,0.87646484375 2.4658203125,1.00830078125 2.15006494522095,1.14013671875 1.89534497261047,1.3134765625 1.70166015625,1.5283203125 1.50797510147095,1.7431640625 1.357421875,1.97916698455811 1.25,2.236328125 1.06770825386047,2.67903661727905 0.97656238079071,3.1591796875 0.9765625,3.6767578125 0.97656238079071,4.31477880477905 1.08642566204071,4.8486328125 1.30615234375,5.2783203125 1.52587890625,5.7080078125 1.845703125,6.02701830863953 2.265625,6.2353515625 2.68554663658142,6.44368493556976 3.13151025772095,6.5478515625 3.603515625,6.5478515625 4.013671875,6.5478515625 4.4140625,6.46891278028488 4.8046875,6.31103515625 5.1953125,6.15315759181976 5.49153614044189,5.98470056056976 5.693359375,5.8056640625 L 5.693359375,4.47265625 Z\" id=\"path1\" style=\"fill:#000000;fill-opacity:1;stroke:none\" />" +
"</g></svg>";

 

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Regular Contributor
mobiledeveloper
Posts: 78
Registered: ‎04-05-2010
My Device: Storm

Re: Regarding conversion and panning of SVG

Thanks, I will implement it and if able to successfully implement will let you know.