user1024882
user1024882

Reputation: 43

Is it possible to add transparency to jpg in Java and Android

I want to load some images to the cloud, but I want to add some protections when someone views the photos and saves the images; they will not see anything because of the transparency.

would the code be common for Java and Android? I would like to prototype it in Java first.

I have found some code that combines two files. One file is my main file the other is a transparent file. The combined file does not have a transparent overlay.

Do I need to use an image drawing order? http://www.developer.nokia.com/document/Java_Developers_Library_v2/GUID-D3E35E6F-0C45-48ED-B09D-F716E14C1C02/javax/microedition/amms/control/imageeffect/OverlayControl.html

    BufferedImage image = ImageIO.read(new File("rose.jpg"));
    BufferedImage overlay = ImageIO.read(new File("myimg1.gif"));


    // create the new image, canvas size is the max. of both image sizes
    int w = Math.max(image.getWidth(), overlay.getWidth());
    int h = Math.max(image.getHeight(), overlay.getHeight());
    BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

    // paint both images, preserving the alpha channels
    Graphics g = combined.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.drawImage(overlay, 0, 0, null);

    // Save as new image
    ImageIO.write(combined, "PNG", new File("combined.png"));

Upvotes: 0

Views: 215

Answers (2)

skgskg
skgskg

Reputation: 1923

You can actually put a trans image as an overlay to the orginial image, that will Protect from download, I think this is usually done by the server side aka your cloud I know from some websites that they use some kind of an overlay such as yours And the browser can't see the image below so you can't download.

I actually didn't understand how you implementing this - the image is opened in the browser?

Just a wild though, you can also cut the image into pieces like a jigsaw puzzle The device won't have problems connecting it togther but when you download you'll Download only "one piece of the puzzle" :-P

Upvotes: 0

Matthew Flaschen
Matthew Flaschen

Reputation: 284786

This won't work. If they can see the image, they can copy it, one way or another. A solution to consider is providing watermarked thumbnails at no charge, then only offering the full resolution image for a fee. However, they can still copy the full resolution image once they pay.

Upvotes: 1

Related Questions