Results 1 to 6 of 6

Thread: Replace Image In SVG

  1. #1
    Join Date
    Jun 2009
    Posts
    87

    Replace Image In SVG

    Hello, to everyone. I want to simply replace the SVG File from Embedded image. I have tried to use the Syntax as below for that:
    Code:
    image.setTraitNS(..............................);
    If I make use of the Sun Emulator then it works fine, but as I am making use of the Nokia S60 FP1 it is not working on it. When I try to do this, the existing image gets disappeared. And nothing will be given in the output. So, if you are having any solution for that then please provide that to me.

  2. #2
    Join Date
    Jan 2006
    Posts
    7,109

    Re: Replace Image In SVG

    Hey, I am also making use of the Same solution for my Nokia. When I tried to do the work as you have done, I also didn't able to get anything. So, if you get any solution then forward that to me. So, I can also solve my problem. I have tried to make use of the internet for this purpose, but I don't find anything which will be helpful in this situation. So, if anyone had done the research on this and having any sort of solution, then please provide that to me.

  3. #3
    Join Date
    Jan 2006
    Posts
    6,878

    Re: Replace Image In SVG

    Hi, I think that you need to make use of the new code for your program. It may be possible that you are getting the problem due to the syntactical changes. So, if you are having any problem due to that, then simply try to use the syntax below:
    Code:
    reqImage = (SVGImage) SVGImage.createImage(getClass().getResourceAsStream("pic.svg"), new SvgImageLoader());
    If you make use of this, then it will simply set that image loader class when you create the SVGImage.

  4. #4
    Join Date
    May 2008
    Posts
    5,937

    Re: Replace Image In SVG

    Hello, I would suggest you to simply make use of the SVG Image and Background Image Replacer for your problem. It is having features as below:
    • Future-proof – Checks for actual support, no browser sniffing
    • Unobtrusive – Only affects browsers with support, uses fallback content without support or if javascript is disabled
    • Simple to use – Just include one javascript file to your pages and use the appropriate image names
    • Small file – Only 1.8 KB

  5. #5
    Join Date
    Jan 2006
    Posts
    4,545

    Re: Replace Image In SVG

    Hello, in your requestResource() method it is necessary to decode the Base64 String. For that purpose you can simply make use of the code below:
    Code:
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import javax.microedition.m2g.ExternalResourceHandler;
    import javax.microedition.m2g.ScalableImage;
    
    public class SVGLoad implements ExternalResourceHandler {
        public void requestResource(final ScalableImage scalableImage,
                final String Str) {
            final InputStream iStream;
            System.out.println("Request For Resource " + Str);
            try {
                if (Str.startsWith("data:image")) {
                    int start = Str.indexOf("base64,") + 7;
                    String encoded = Str.substring(start);
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    Base64.decode(encoded, bos);
                    iStream = new ByteArrayInputStream(bos.toByteArray());
                    scalableImage.requestCompleted(Str, iStream);
                    return;
                } else {
                    iStream = getClass().getResourceAsStream(Str);
                    if (iStream == null) {
                        System.out.println("Failed to load " + Str + "!");
                    }
                    scalableImage.requestCompleted(Str, iStream);
                }
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
    }

  6. #6
    Join Date
    Jun 2010
    Posts
    1

    Re: Replace Image In SVG

    This is pretty cool. I do something similar, but with SVG and not geared towards text. The idea is if the browser supports SVG, let it render it, otherwise send it back to the server to be rendered as PNG. The advantage of using SVG for something like this would be a native-browser implementation, and a fallback to PNG rendered on the server for browsers that don’t do SVG. Also, the fonts would be rendered consistently, for example using the standard web fonts, but applying strokes, filters, transforms, text on a path, etc.
    Last edited by Maqbool; 30-06-2010 at 09:31 AM. Reason: External Links Not Allowed, Removed The Same.

Similar Threads

  1. Replies: 7
    Last Post: 15-02-2012, 05:29 AM
  2. Replies: 4
    Last Post: 09-08-2010, 02:51 PM
  3. Replies: 4
    Last Post: 28-01-2010, 10:15 PM
  4. Html replace browse image upload
    By Brunoz in forum Software Development
    Replies: 3
    Last Post: 04-08-2009, 03:24 PM
  5. Replies: 3
    Last Post: 14-04-2008, 03:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,354,131.34612 seconds with 16 queries