Prob in saving canvas to jpg

hi friends, i m tryin to save canvas to jpg n has de code for it but saved jpg file contalins black background... i hav attached de code.. can u plz execute it n suggest wat de prob is.....import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
public class CanvasClip extends Canvas implements ActionListener
    Rectangle clip;
    boolean showClip;
    public CanvasClip()
        clip = new Rectangle(50, 150, 350, 300);
        showClip = false;
    public void paint(Graphics g)
System.out.println("inside");
        super.paint(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        int w = getWidth();
        int h = getHeight();
        int dia = Math.min(w,h)/4;
        g2.setPaint(getBackground());
        g2.fillRect(0,0,w,h);
        g2.setPaint(Color.blue);
        g2.drawRect(w/16, h/16, w*7/8, h*7/8);
        g2.setPaint(Color.red);
        g2.fillOval(w/8, h/12, w*3/4, h*5/6);
        g2.setPaint(Color.green.darker());
        g2.fillOval(w/2-dia/2, h/2-dia/2, dia, dia);
        g2.setPaint(Color.orange);
        g2.drawLine(w/16+1, h/16+1, w*15/16-1, h*15/16-1);
        if(showClip)
            g2.setPaint(Color.magenta);
            g2.draw(clip);
    public void actionPerformed(ActionEvent e)
        Button button = (Button)e.getSource();
        String ac = button.getActionCommand();
        if(ac.equals("show"))
            showClip = !showClip;
            repaint();
        if(ac.equals("save"))
            save();
    private void save()
        int w = clip.width;
        int h = clip.height;
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = img.createGraphics();
        g2.translate(-clip.x, -clip.y);
        paint(g2);
        g2.dispose();
        String ext = "jpg";  // or "png"; "bmp" okay in j2se 1.5
        try
            ImageIO.write(img, "jpg", new File("canvasClip.jpg"));
        catch(IOException ioe)
            System.err.println("write error: " + ioe.getMessage());
    private Panel getUIPanel()
        Button show = new Button("show clip");
        Button save = new Button("save");
        show.setActionCommand("show");
        save.setActionCommand("save");
        show.addActionListener(this);
        save.addActionListener(this);
        Panel panel = new Panel();
        panel.add(show);
        panel.add(save);
        return panel;
    public static void main(String[] args)
        CanvasClip cc = new CanvasClip();
        Frame f = new Frame();
        f.addWindowListener(new WindowAdapter()
            public void windowClosing(WindowEvent e)
                System.exit(0);
        f.add(cc);
        f.add(cc.getUIPanel(), "South");
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}I beleive u can get de wat prob is... if not ask me to b more clear

Hi philihop,
Firstly, thanks for your code and it helps me do my job.
Please read the following words if you haven't solved this problem.
Canvas paint method use Graphics object 'g' to draw something in the canvas. Its default value is black when you output to JPG image. That is the reason why it prints black background on jpg image. So please just add
int width = getWidth();
int height = getHeight();
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
This 4 lines code draw the whole display area in Color.white. And problem is solved.
Byron
Message was edited by: Byron on 29/01/2007
byronzh

Similar Messages

  • Issue with saving Tiff as JPG

    I am an artist who is using Photoshop Elements 4. Recently, my photogrpaher took photos of my work in TIFF format and sent me a CD of the shoot. I opened one in photoshop, edited it and tried to save it as jpg. I kept getting a window which read: Could not complete your request because of a program error.
    My photographer and I are confused because this has never happened. I opened up a CD of his photos from a previous shoot to check and see if they could be saved as a jpg and had no problem. He uses a Nikon D700 and has not changed anything else.
    This is frustrating because I use these images for my business, etc. Granted, elements 4 is an older program but why now?
    I'd appreciate any help!   Thanks!

    There is an asterisk after the 8. Like:  RGB/8*
    Since your post my photographer figure out a quick fix for this crazy
    dilema. He had me open one of the TIFFS and save it as a PSD. Then, I copied
    it and pasted into a new blank file. I then was able to save it as a JPEG.
    He and I are still stumped over this but I'll be needed new photos soon and
    we'll see if this happens again. Thanks for your help.

  • Can an InDesign page be saved as a jpg file for use in Photoshop CS5 ?

    Can an InDesign page be saved as a jpg file for use in Photoshop CS5 ?

    mckayk_777 wrote:
    Just wondering peter what you think, instead of output to pdf you copy and then create create new file in photoshop and paste into that file. Is that sort of the same thing?
    Seems to be ok especially if you enlarge the object before you copy it into photoshop.
    I think what you are pasting (never bothered to try this) is just the screen preview, hence the need to enlarge. Why would you waste your time doing that instead of exporting to a high-res PDF?
    If you want only part of the page, check out http://indesignsecrets.com/free-layout-zones-add-on-is-incredible-productivity-tool.php

  • Is there anyway to retain layers in Photoshop Elements while saving to a .jpg format?

    I'm new to using PSE, and I like their concept of layers so that the original photo is not altered, however, my preference is to save all of my files utilizing .jpg.  I actually found out yesterday that after 3 weeks of scanning in very old family photos, then using PSE11 and utilizing layers and then saving to .jpg, that now when I reopen these files in PSE that the layers created are gone.  Please help!

    roberta5419014 wrote:
    Hi, although I'm really disappointed to hear that JPEG file format does not allow one to preserve the layer structure, I like your suggestion to keep the original psd files on a separate external drive.  I'm undertaking a massive job to scan in and then photoshop several generations of photos (estimated at over 8,000 photos), and as mentioned before I'd like to have all finished files saved as jpegs, but doing minimum compression as I know that it's a lossy format.  I guess I'll need to think what's the likelihood of wanting to access the original photos again in psd so that the background layer is preserved.  One last question if I may, you mentioned that converting over to jpeg is easy enough to do.  Is it simply a matter of selecting each PSD file and saving as a .jpg or is there a faster and or bulk method to convert multiple files to jpeg?  Thanks for all your help in fielding these questions?
    If you google "batch conversion PSD to JPEG" you will get many hits for converters.
    Your proposed work-flow is not clear to me. Are you planning to scan these photos and process all of them in PSE, then save them in PSD with the layers intact? Or, are you planning  to scan them and simply save the scans without initial PSE processing?
    I bring this up as I did a project last year, scanning/digitizing old 2x2" Kodacolor slides in the cardboard mounts. Initially I just scanned them and saved them to disk as JPEG. On further review, some were not interesting, others had folks in them whose identity remains cryptic, etc. The bottom line is that I was selective in processing them in PSE.
    I wouldn't worry about JPEG compression as a deterrent unless you Open>modify>save, Open>modify>save repeatedly.

  • Why is my iPad pages file saved as a jpg on my mac?

    Why us my iPad pages file saved as a jpg on my MAC after transfer?

    I am un-employed therefore I can't afford an iPad but, I vaguely remember the propaganda saying you could transfer these documents via iCloud.
    I guess this is called iWork.com now
    http://www.apple.com/iwork/iwork-dot-com/

  • Photoshop CS - Saving file as jpg

    Hi
    I am using CS v8.0 and using a javascript action script. I seem to be having all kinds of problems saving the document as a .jpg though. I simply want to open all the files in a folder, resize the image and save the file with a different name (in the same folder). Here is my code so far:
    // Save current dialog preferences
    var startDisplayDialogs = app.displayDialogs;
    var startRulerUnits = app.preferences.rulerUnits; // Save the current preferences
    app.preferences.rulerUnits = Units.PIXELS; // Set Photoshop to use pixels
    // Don't display dialogs
    app.displayDialogs = DialogModes.NO;
    var FILE_TYPE = ".jpg"; // The type of files that this script works on -- you can change
    var SEARCH_MASK = "*" + FILE_TYPE; // Image file filter to find only those files
    try {
    // Ask user for input folder
    var inputFolder = Folder.selectDialog("Select a folder to process");
    if (inputFolder == null)
    throw X_NOINPUT;
    // get all files in the input folder
    var fileList = inputFolder.getFiles(SEARCH_MASK);
    // Open each file in turn
    for (var i = 0; i < fileList.length; i++) {
    // Set document to open file
    var docRef = open(fileList[i]);
    var fname = docRef.name;
    var currentDocument = app.activeDocument;
    // IF LandScape Picture
    if (currentDocument.height.value < currentDocument.width.value) {
    // Resize image by shrinking width
    currentDocument.resizeImage(110,undefined);
    // IF Height < 110 --- Enlarge top right of canvas
    if (currentDocument.height.value < 110) {
    currentDocument.resizeCanvas(110,110,AnchorPosition.BOTTOMLEFT);
    docRef.backgroundLayer.applySharpen();
    var saveFile = new File(fname.slice(0,-4) + "-small.jpg");
    var saveOptions = new JPEGSaveOptions();
    saveOptions.quality = 3;
    currentDocument.saveAs(saveFile,saveOptions,true,Extension.LOWERCASE);
    currentDocument.close(saveOptions.DONOTSAVECHANGES);
    } else {
    currentDocument.close(saveOptions.DONOTSAVECHANGES);
    } else {
    // Resize image by shrinking height
    currentDocument.resizeImage(undefined,110);
    // IF Width < 110 --- Enlarge right of canvas
    if (currentDocument.width.value < 110) {
    currentDocument.resizeCanvas(110,110,AnchorPosition.BOTTOMLEFT);
    docRef.backgroundLayer.applySharpen();
    var saveFile = new File(fname.slice(0,-4) + "-small.jpg");
    var saveOptions = new JPEGSaveOptions();
    saveOptions.quality = 3;
    currentDocument.saveAs(saveFile,saveOptions,true,Extension.LOWERCASE);
    currentDocument.close(saveOptions.DONOTSAVECHANGES);
    } else {
    currentDocument.close(saveOptions.DONOTSAVECHANGES);
    catch (exception) {
    // Show degbug message and then quit
    alert(exception);
    finally {
    // Reset app preferences
    app.displayDialogs = startDisplayDialogs;
    The resize of the image seems to work fine but i just can't get the saving working. Also, even though i have specified DONOTSAVECHANGES i still get the "Do you want to save changes" prompt when closing the file.
    Any help is appreciated..
    Thanks,
    Dan

    With CS2, you have to make sure the image is flattened, there are not paths, no extra channels, in RGB colorspace, and 8bit.  The current versions of PS does this for you, but not CS2.
    BTW, you said you just installed CS2, which is a very old program.  I hope you have a license for it.  See this thread:
    https://forums.adobe.com/message/6290183#6290183

  • Saving files as .jpg, not .eps?

    I've moved up from CS5 to 6. Always before able to save images as .jpg. Now on 6, files are saved as .eps?
    Why is that and how can I save as .jpg instead?

    Hi Tallarchitect,
    The way you save files in Photoshop has changed very little over the last few years. You are able to choose a variety of file formats, .eps and .jpeg being two of them.
    You can change the file format you want to save by selecting "JPEG" from the Format menu after opening the Save As… dialog.

  • Saving canvas as an image: embedded in an applet

    hi everyone,
    I'm trying to save shapes I've drawn in a canvas as a jpg. This works, thanks to a solution I found somewhere in one of these forums. However, I need to embed the application in an applet, and in that case it doesn't work anyone. Here is some code that works when I don't use applets:
    public class MenuItemHandler implements ActionListener{
              public void actionPerformed(ActionEvent e) {
                   try{
                        FileDialog fd = new FileDialog(new Frame(), "Save as JPG", FileDialog.SAVE);
              fd.setFile("canvas.jpg");
              fd.setVisible(true);
              String name = fd.getDirectory() + fd.getFile();
              File file = new File(name);
                        ImageUtils utils = new ImageUtils();
                        BufferedImage image = utils.createComponentImage(tc);
                        utils.encodeImage(image,file);
                   catch(Exception ex) {
                        ex.printStackTrace(); }
         class ImageUtils {
              private JPEGImageEncoder encoder = null;
              private FileOutputStream fileStream = null;
              public BufferedImage createComponentImage(Component component){
                   BufferedImage image = (BufferedImage)component.createImage(component.getWidth(),component.getHeight());
                   Graphics graphics = image.getGraphics();
                   if(graphics != null) { component.paintAll(graphics); }
                   return image;
              public void encodeImage(BufferedImage image, File file) throws IOException{
                   fileStream = new FileOutputStream(file);
                   JPEGEncodeParam encodeParam = JPEGCodec.getDefaultJPEGEncodeParam(image);
                   encoder = JPEGCodec.createJPEGEncoder(fileStream);
                   encoder.encode(image,encodeParam);
                   fileStream.close();
    When the code is embedded in an applet, I see my appliaction and I get my save dialog box, but there won't be written any file anymore. I suppose it has something to do with the fact that I don't use getDocumentBase() or getCodeBase(), but I'm not sure about that, and if this is the reason, I don't know exactly how to implement it in the code.
    I hope that someone can help me!!
    Thanks in advance!

    hi everyone,
    I'm trying to save shapes I've drawn in a canvas as a jpg. This works, thanks to a solution I found somewhere in one of these forums. However, I need to embed the application in an applet, and in that case it doesn't work anyone. Here is some code that works when I don't use applets:
    public class MenuItemHandler implements ActionListener{
              public void actionPerformed(ActionEvent e) {
                   try{
                        FileDialog fd = new FileDialog(new Frame(), "Save as JPG", FileDialog.SAVE);
              fd.setFile("canvas.jpg");
              fd.setVisible(true);
              String name = fd.getDirectory() + fd.getFile();
              File file = new File(name);
                        ImageUtils utils = new ImageUtils();
                        BufferedImage image = utils.createComponentImage(tc);
                        utils.encodeImage(image,file);
                   catch(Exception ex) {
                        ex.printStackTrace(); }
         class ImageUtils {
              private JPEGImageEncoder encoder = null;
              private FileOutputStream fileStream = null;
              public BufferedImage createComponentImage(Component component){
                   BufferedImage image = (BufferedImage)component.createImage(component.getWidth(),component.getHeight());
                   Graphics graphics = image.getGraphics();
                   if(graphics != null) { component.paintAll(graphics); }
                   return image;
              public void encodeImage(BufferedImage image, File file) throws IOException{
                   fileStream = new FileOutputStream(file);
                   JPEGEncodeParam encodeParam = JPEGCodec.getDefaultJPEGEncodeParam(image);
                   encoder = JPEGCodec.createJPEGEncoder(fileStream);
                   encoder.encode(image,encodeParam);
                   fileStream.close();
    When the code is embedded in an applet, I see my appliaction and I get my save dialog box, but there won't be written any file anymore. I suppose it has something to do with the fact that I don't use getDocumentBase() or getCodeBase(), but I'm not sure about that, and if this is the reason, I don't know exactly how to implement it in the code.
    I hope that someone can help me!!
    Thanks in advance!

  • Problem in saving image to jpg

    Hello.
    I've got a problem in saving a LabView Picture in a jpg File.
    The picture id grabbed from a DirectX Livestream from a camera.
    Then I want to save it in a jpg file using the Standard LabView Functions.
    But all I get is an empty jpg File and an error:
    Check_Data_size.vi
    Error 1
    I'm using LabView 7.1.
    Has anybody got an idea how to solve the problem?

    No.  You can save a gray image to jpg, but I has to be 24 bit.
    Try save your data to bmp.  If you got the same problem, that means you fail to wire correct data format to the LabVIEW VI you're using.
    George Zou
    http://gtoolbox.yeah.net
    George Zou
    http://webspace.webring.com/people/og/gtoolbox

  • Problem with layers in saving logo as jpg

    Hi- I created a logo in Illustrator and brought it into Photoshop. I wanted to save it as a .jpg in My Pictures to upload it to a website. But when I tried to change from the file extension psd to jpg, I got a dialogue box which says I'll have to save it as a copy. Under Save Options, there is a caution sign next to Layers. Under Color, it's checked next to the ICC Profile: US Web Coated (SWOP)v2. Also checked is Use lower case extension. When I save it as a jpg anyway and try to upload it to the site, it shows up as a box with an "X" in it. Can someone tell me what I've done incorrectly? Thanks!

    OK, no problem. Here's the process I've been going through. I click Save
    As. A dialogue box appears with "Save As" at the top. I save it in My
    Pictures, as this is where I access images for this website. Under
    "Format", I select .jpg. As soon as I do this, in the "Save Options"
    section below, I see a yellow caution sign next to "layers" and at the
    bottom a message appears which says, "File must be saved as a copy with
    this selection". This is confusing, since I've gone through this process
    before with other logos without having this problem. I'm wondering if it
    has to do with the Illustrator file I originally brought into Photoshop.
    Thanks for your help.

  • Saving tiff or jpg files within a single, existing psd file without creating new files

         Hi, I just bought CS5 and I wonder if it is possible to save multiple images that are created within a single psd file in jpg or other image file formats without creating new psd files, but rather saving them as "embedded" within the single psd file in whih they are created. For example, one could select a portion of an image that one has created, and save just that selection as a jpg without leaving the existing psd file, and after that, one could select another portion of the same image and save it as a tiff, etc. Is this possible?
    Much thanks.

    No and Yes!
    You can do much of what you want, but not exactly as you described it.  You can certainly make multiple selections and have them saved in the psd file. You can also save jpg version of those selections, but you have to do a little extra work.
    Lets say, by way of example, you have an image and you want to make three different selections within that image, save each selection as a jpeg, and save those selections along with the full image as a psd file. You can do the following, which is just one way of several to proceed, with your image opened.
    1. Make selection 1, hit Ctrl+J to jump that selection to a new layer
    2. Make selection 2, hit Ctrl+J to jump that selection to a new layer
    3. Make selection 3, hit Ctrl+J to jump that selection to a new layer
    4. Alt click on the layer with selection 1. This makes only that layer visible.
    5. Click on Layer > Duplicate Layer > destination New > give it a name
    6. This creates a new (temporary document). Open it.
         click Image > Trim > transparent pixels
         click Save for Web & Devces, select your parameters and save your jpeg
         Close and discard this temporary file.
    7. Repeat steps 4,5 & 6 for selection 2 & selection 3
    8. Save your psd file
    You now have three jpegs and a psd file with all the information to create or modify the original selections
    Paulo

  • What are the best font and settings to use in a psd when saving, noticed some jpgs (hires) still dont pick up all the words used., What are the best font and settings to use in a psd when saving, noticed some jpgs (hires) still dont pick up all the words

    Just to elaborate on the question, i have a number of adverts designed in photoshop and saved as hi resolution jpgs however when opening them in acrobat and using OCR i noticed that either none of the text is picked up or partially picked up. are there fonts that are better or settings for the fonts that would make the recognition better and more reliable.
    Thanks

    tried that today, was a little better, somewhere around 40% words get picked up although sometimes far less or none. tried so many settings, i think its just one of those things, its not really designed to handle all that well.

  • Pb displaying image in a canva with jpg format

    I have an applet that displays images in a canva by pushing buttons. It works very well with gif image but bad with jpg image.
    Coincidence or not ? I don't know.
    What I know that I use the same method painting jpg or gif image
    (first changing image name then calling mycanva.validate() and mycanva.repaint() and of course mycanva paint method contains g.drawimage(myimage,0,0,200,200,this) )
    With jpg image what happens is the image is not completly painted (sometime half painted, sometime less than half painted) and if I do reload the browser the image is very well displayed...
    has someone an idea ?
    many thanks

    try your app on another computer and see if it does the same thing. I had a very similar problem and it turned out to be my video driver was not driving my video properly. I changed/updated the video driver and my problems were totally solved.

  • CS3 Illustrator is what I am using.  I cannot seem to select just the artwork to export to JPG or PNG.  When I do, it exports the entire work space.  I just want the art work saved to a jpg.  What are the instruction sets to convert only the art work obje

    Can someone tell me how to export my art work object to a PNG or JPG?  I am getting the whole work space saved when I export.    I want to export a label to another print program and the entire workspace is in the JPG including not just the art I want, but anything else that is on the work space.       How can I isolate just the object I want to export and convert it?Newsgroup_User

    Randy,
    You may create a rectangle the size of the artwork and Object>Crop Area>Make, then Save for Web.
    Or you may use the Crop Area Tool, see the documentation or here,
    http://designertoday.com/Tutorials/Illustrator/4822/Using.the.Crop.Tool.Illustrator.CS3.Tu torial.aspx

  • Saving .psd as .jpg crashes Photoshop CS4

    I recently upgraded to CS4, and am having a problem saving a flattened .psd file to .jpg (saving to any other format works just fine). When I try to save as a .jpg (RGB, 8-bit), the program partially locks up, and no .jpg file is created. The File menu has only two or three options, including Close and Open As, but I cannot actually select these options. All other menu options are grayed out; no tools work. I cannot quit Photoshop in this state without using Task Manager.
    Any ideas about what's going on? Thanks!

    Try resetting your preferences as described in the FAQ.
    http://forums.adobe.com/thread/375776?tstart=0
    You either have to physically delete (or rename) the preference files or, if using the Alt, Ctrl, and Shift method, be sure that you get a confirmation dialog.
    This resets all settings in Photoshop to factory defaults.
    A complete uninstall/re-install will not affect the preferences and a corrupt file there may be causing the problem.

Maybe you are looking for

  • Share 2 Accts on 2 computers?

    My wife and I each have iPods with two separate iTunes accounts on two separate computers. What is the best way for us to share songs? Irv

  • Some initialization parameters

    hi masters, i was looking for documentation on some initialization parameter, complexview_merging pushjoin_union_view but i didn't get a good one.. i would like to know for what purpose '_complex_view_merging' is used? as we all know that pushjoin_un

  • Processing in STP causes out-of-sync in FCP

    Mixing multitrack live band performances. After sending tracks to Soundtrack Pro for normalization, EQing, effecting etc. and round tripping back to FCP they now get out of sync with live performance video over the course of time. Doesn't happen if I

  • Delete P-P CS6 after CC installation?

    New to the Premiere-Pro and video side of things ... Lightroom's last few iterations have installed themselves and 'de-installed' my previous programs, nicely saving computer space (though I know some don't like that behavior). I just up-dated to CC

  • The file could not be imported: There is not enough disk space left

    The file could not be imported: There is not enough disk space left to import why? I have 53.1 Gb left and I can import the whole movie but when I broke it up into chapters to edit it will only import 2 edited chapters I don't like imovie anyone ??