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
Developer
sonicboomboy
Posts: 466
Registered: ‎03-04-2009
My Device: 8520
My Carrier: some

SVG image, gradient lost.

[ Edited ]

Folks,

 when creating Bitmap from svg file I see that gradient colors are missed.  Please find below code snippet:

 

SVGImage svgImage = SVGImage.createImage(inputStream, null);
svgImage.setViewportWidth(image.width);
svgImage.setViewportHeight(image.height);

SVGSVGElement svgElement = (SVGSVGElement)svgImage.getDocument().getDocumentElement();
svgElement.setFloatTrait("width", svgImage.getViewportWidth());
svgElement.setFloatTrait("height", svgImage.getViewportHeight());

Bitmap bitmap = new Bitmap(image.width, image.height);
bitmap.setARGB(new int[image.width * image.height], 0, image.width, 0, 0, image.width,image.height);

Graphics graphics = Graphics.create(bitmap);

ScalableGraphics scalableGraphics = ScalableGraphics.createInstance();
scalableGraphics.bindTarget(graphics);
scalableGraphics.setRenderingQuality(ScalableGraphics.RENDERING_QUALITY_HIGH);
scalableGraphics.render(padding.left, padding.top, svgImage);
scalableGraphics.releaseTarget();

// now bitmap is ready.

 

any thoughts would be very appreciated!

Got resolved! Press kudo icon!
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: SVG image, gradient lost.

This might be a device issue.  Review this Thread for further information.  I think that OS 7.0 devices all have 32 bit color screens so this problem might be historical now.

Please use plain text.
Developer
sonicboomboy
Posts: 466
Registered: ‎03-04-2009
My Device: 8520
My Carrier: some

Re: SVG image, gradient lost.

if I save SVG image onto device and then open it via FileExplorer app, the SVG is rendered properly. So i'm not sure if it's a device issue. I think i need to set some additional properties while converting from SVG to Bitmap, But can't figure it out what.
Got resolved! Press kudo icon!
Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: SVG image, gradient lost.

[ Edited ]

The SVG rendered directly may be handled differently than the Bitmap. I know in the past we've had issues with gradients on Bitmaps not being smooth (they appeared banded/blocky). How great is the color different between the gradient edges? If the colors are not that different, try using something like black to white or red to green, and see what it does.

Please use plain text.
Developer
sonicboomboy
Posts: 466
Registered: ‎03-04-2009
My Device: 8520
My Carrier: some

Re: SVG image, gradient lost.

From what i see it just renders those areas (supposed with gradient) with solid white color. We ended up using SVG without gradient , just for now.

mreed,

As you've mentioned gradient problem with Bitmaps do you know any solution for this? As I experience this kind of issue as well in my app.
Got resolved! Press kudo icon!
Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: SVG image, gradient lost.

The devices support (or used to only support) a specific color space. At the time we were using transparent PNG images with the gradient when we saw the issue. I think we converted all the images to the required color space and it mostly fixed the issue... but I don't recall it ever being perfect. Gradients on BlackBerry has always been a sore subject.

 

http://www.blackberrydev.net/wiki/Profiling_and_Optimization

Please use plain text.
Developer
sonicboomboy
Posts: 466
Registered: ‎03-04-2009
My Device: 8520
My Carrier: some

Re: SVG image, gradient lost.

gotcha you.

Apparently on BB 7 this is improved. As UI rendering is quite compelling. Other than that is 'glitchy'
Got resolved! Press kudo icon!
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: SVG image, gradient lost.

Sorry, didn't realise I had not pasted in my link.  Here it is now....:

http://supportforums.blackberry.com/t5/Java-Development/Gradient-Poor-Quality/m-p/778325

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: SVG image, gradient lost.

If memory serves me right, BlackBerry supports SVG Tiny. SVG Tiny has no support for gradients. The proper thing for a SVG parser to do when it encounters something it doesn't support is to ignore it. This may be the issue you have.
---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.
Please use plain text.
Developer
sonicboomboy
Posts: 466
Registered: ‎03-04-2009
My Device: 8520
My Carrier: some

Re: SVG image, gradient lost.

@rcmaniac25,
but how to explain that if you open SVG image in File app (bb native app), and it renders perfectly.
Got resolved! Press kudo icon!
Please use plain text.