JAI - Saved image has black background (unless screen config is True Color)

Hi!
I'm trying to save images using JAI's codecs. Everything is okay if screen config is True Color, but if in 256 colors (or even in 65536 colors) the background of my images looks very dark...
Can you please have a look at the code bellow (and try it with some different screen configs). I'm really stuck with that issue; any suggestion may help...
NOTE:
- I've noticed this problem when using JAI's jpeg codec.
- The problem occurs with both JDK 1.3 and 1.4.
- The problem does not occur (only) if screen config is True Color.
- You must rerun the code after changing screen config.
Thanks for help...
cbmn2
+++++++++++++++++++
import java.awt.*;
import com.sun.media.jai.codec.*;
import javax.media.jai.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.awt.image.renderable.*;
public class Test2 extends JFrame
String codecFormat = "jpeg";
String outFilePath = "./test.jpg";
JPanel jp;
JButton jb;
MyActionListener mal = new MyActionListener();
public Test2()
setSize(800,600);
Container cp = getContentPane();
cp.setLayout(null);
jp = new JPanel(){
public void paintComponent(Graphics g)
super.paintComponent(g);
Dimension dim = getSize();
// initialization...
//==================
g.setColor(Color.white);
g.fillRect(0, 0, dim.width, dim.height);
// some drawing...
//=================
int inset = 10;
g.setColor(Color.red);
g.fillRect(inset, inset, dim.width-2*inset, dim.height-2*inset);
jp.setBounds(10,10,400,300);
jp.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
cp.add(jp);
jb = new JButton("Save image to '"+outFilePath+"'");
jb.setBounds(10,320,400,50);
jb.addActionListener(mal);
cp.add(jb);
class MyActionListener implements ActionListener
public void actionPerformed(ActionEvent ae)
Object source = ae.getSource();
if (source == jb)
jb_actionPerformed(ae);
public void jb_actionPerformed(ActionEvent ae)
try {
Image image = jp.createImage(jp.getWidth(), jp.getHeight());
jp.paint(image.getGraphics());
saveImage(image, outFilePath, codecFormat);
JOptionPane.showMessageDialog(this, "File '"+outFilePath+"' is now saved...");
catch(Exception e) {
JOptionPane.showMessageDialog(this, "Oops! An exception occured...");
public void saveImage(Image image, String filePath, String format) throws Exception
// conversion Image => RenderedImage
//==================================
RenderedImage renderedImage = JAI.create("AWTImage", image);
ParameterBlock pb = new ParameterBlock();
pb.addSource(renderedImage);
pb.add(DataBuffer.TYPE_BYTE);
renderedImage = JAI.create("format", pb);
// saving file
//=============
JAI.create("filestore", renderedImage, filePath, format);
public static void main(String[] args)
(new Test2()).setVisible(true);
}

try this:
BufferedImage bi = new BufferedImage(1728,500,BufferedImage.TYPE_BYTE_BINARY);
Graphics2D big = bi.createGraphics();
Graphics2D g2 = bi.createGraphics();
big.setFont(new Font("Dialog", Font.PLAIN, 20));
big.setColor(Color.WHITE);
big.fillRect(0,0,1728,500);
big.setColor(Color.BLACK);
big.drawString("Data/Time Created:" + new java.util.Date(), 80, 210);
big.drawString("POLICY NUMBER: 1711215 NAME OF CALLER: BENEFICIARY", 80, 230);
big.drawString("Requested: Loan Request XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Current Loan Value: $0.00", 80, 270);
g2.drawImage(bi, 0, 0, null);

Similar Messages

  • Using Photoshop elements 11 on a PC, when I put new photo on screen to edit the background goes to black which messes me up when making a thumbnail that has black background.  How do I get the background to white as it was originally?

    Using Adobe photoshop elements 11 on a PC.  When I put a photo up to edit the background on the page goes black.  I need it to go back to white to do a thumbnail that has black background so I can see it.  How do I do that.  It used to be white on the background.  Don't know how I got it all black. Can you help?

    If you mean by "background" the blank work area that presents when you open the Editor, then right click on it and reset to white.
    If I have this wrong, please rephrase your inquiry.

  • Using binarize... Getting Tiff Image in Black Background..

    Hi,
    Basically my subject summarizes my problem, but I am trying to write some text to a blank JPEG file and then create a Tiff file from that JPEG...
    But When i use the binarize i am getting the image as black background and the resolution is not that great...
    I am using binarize, because i need to use TIFFEncodeParam.COMPRESSION_GROUP4 but i was getting bi-level error, that is why i am using binarize to create a GROUP4 with black and white color to minimize the file size...
    I am posting the source code, i would appreciate someone can take a look at this code and figure out why i am getting black background...in the tiff file...
    Any help will be greatly appreciated...
    Thanks in advance...
    ========================================
    import javax.swing.UIManager;
    import java.awt.*;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2003</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class Application1 {
    private boolean packFrame = false;
    //Construct the application
    public Application1() {
    Frame1 frame = new Frame1();
    frame.setVisible(true);
    //Main method
    public static void main(String[] args) {
    new Application1();
    ================================================
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import com.sun.image.codec.jpeg.*;
    import com.sun.media.jai.codec.*;
    import javax.media.jai.*;
    import java.awt.image.BufferedImage;
    import java.awt.image.RenderedImage;
    import java.awt.image.DataBuffer;
    import java.awt.geom.GeneralPath;
    import java.io.*;
    import java.awt.image.renderable.ParameterBlock;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2003</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class Frame1 extends JFrame implements java.io.Serializable {
    private JPanel contentPane;
    private JButton jButton1 = new JButton();
    public static final String DEFAULT_FILE = "blank.jpg";
    private static RenderedImage img;
    //Construct the frame
    public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane();
    jButton1.setBounds(new Rectangle(125, 87, 79, 27));
    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton1_actionPerformed(e);
    contentPane.setLayout(null);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame Title");
    contentPane.add(jButton1, null);
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    void jButton1_actionPerformed(ActionEvent e) {
    String fileName = DEFAULT_FILE;
    // Read the image from the designated path.
    System.out.println("load image from '" + fileName+"'");
    PlanarImage src = JAI.create("fileload", fileName);
    // Generate a histogram...
    Histogram histogram = (Histogram)JAI.create("histogram", src).getProperty("histogram");
    // Get a threshold equal to the median..
    double[] threshold = histogram.getPTileThreshold(0.5);
    PlanarImage dst = JAI.create("binarize", src, new Double(threshold[0]));
    BufferedImage bi = dst.getAsBufferedImage();
    Graphics2D big = bi.createGraphics();
    Graphics2D g2 = bi.createGraphics();
    big.setFont(new Font("Dialog", Font.PLAIN, 20));
    big.setColor(Color.black);
    big.drawString("Data/Time Created:" + new java.util.Date(), 80, 210);
    big.drawString("POLICY NUMBER: 1711215 NAME OF CALLER: BENEFICIARY", 80, 230);
    big.drawString("Requested: Loan Request XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Current Loan Value: $0.00", 80, 270);
    g2.drawImage(bi, 0, 0, null);
    try {
    File file = new File("test.tiff");
    FileOutputStream out = new FileOutputStream(file);
    TIFFEncodeParam params = new TIFFEncodeParam();
    params.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
    ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF",out, params);
    if(encoder == null) {
    System.out.println("imageEncoder is null");
    System.exit(0);
    encoder.encode(bi);
    System.out.println("DONE!!!");
    catch (Exception ex) {

    try this:
    BufferedImage bi = new BufferedImage(1728,500,BufferedImage.TYPE_BYTE_BINARY);
    Graphics2D big = bi.createGraphics();
    Graphics2D g2 = bi.createGraphics();
    big.setFont(new Font("Dialog", Font.PLAIN, 20));
    big.setColor(Color.WHITE);
    big.fillRect(0,0,1728,500);
    big.setColor(Color.BLACK);
    big.drawString("Data/Time Created:" + new java.util.Date(), 80, 210);
    big.drawString("POLICY NUMBER: 1711215 NAME OF CALLER: BENEFICIARY", 80, 230);
    big.drawString("Requested: Loan Request XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Current Loan Value: $0.00", 80, 270);
    g2.drawImage(bi, 0, 0, null);

  • Black Background Title Screen

    I am trying to create a black background title screen (with white titles). Suggestions on this board have indicated that I could drag the title bar before the clip begins and that the default color would be black (i.e., solving my problem). I have not been able to drag the title before to an area before the clip begins. Any help would be appreciated.

    OK, I figured it out.

  • My ipod 5th generation has lines on the screen that will change color and the ipod sometimes wont respond when i touch it

    My ipod has lines on the screen and will change color. It also is not responding to my touch. What can i do?

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Restore from backup. See:                                 
    iOS: How to back up           
    - Restore to factory settings/new iOS device.
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar          

  • Toolbar button has black background in GW 7

    Hi
    My C3PO workds beautifully, but not in GW 7. The toolbar button has a
    black background in GW 7 but when I run it with 6.5 or under, it works
    fine.
    I am also calling Documentum components from the GW client and some of
    these forms have a black background in some of the textboxes. Very strange!
    Does any one have a clue?
    Thanks
    Johan van Zyl

    wtjones2 wrote:
    > I have been fighting this as well. I'm using resource ID (digit not
    > string) and 0,255,0 without any luck. Going to just make it grey or
    > something.
    > johanvz wrote:
    > > Hi
    > > My C3PO workds beautifully, but not in GW 7. The toolbar button has a
    > > black background in GW 7 but when I run it with 6.5 or under, it works
    > > fine.
    > > I am also calling Documentum components from the GW client and some of
    > > these forms have a black background in some of the textboxes. Very strange!
    > > Does any one have a clue?
    > > Thanks
    > > Johan van Zyl
    Hi
    Ok I found it. You have to make the background of your image red. This is
    somehow used as a transparent colour in GW 7.
    Cheers

  • Tried to install the latest update on my ipad. i get an image of "itunes" with a connecting cord. hasnt changed in three hours. if i turn it off, it goes right back to same image on black background. i am stuck, please help me, thanks

    i tried to install the latest update on my ipad. i get an image which says I tunes with a cord to plug in. it is on a black background.. it has been like this for three hours now. if i turn it off and then on again that is the only page that appears. i am stuck. please can anyone help me? thanks.

    It's too bad you lost stuff. I would recommend that you back stuff up before the next one. For example, iOS8 will be out sometime this fall. Just in case you experience the same thing again, do a backup before you do the update.

  • After Update Cisco Prime Infrastructure from 1.3 to 2.0 imported floor plans has black background

    Hello everybody,
    we have updated cisco prime infrastructure from 1.3 to 2.0. When we now import a floor plan (autocad-file, dwg-format), the background from finally image, that is show in prime, is black. Previous imported floor planes has a white background. We also tried to import a previous imported floor plan again, the background is now black. Is there a possibilty to change the background to white? Thanks

    Hi,
    Look no further, these issues are related to know bugs. It seems that autocad files have multiple issues with PI 2.0, Only feasible way is to convert them to JPGs and import them. Lets hope these will get fixed to the level they where at PI 1.3.
    CSCuj63017, PI 2.0 dwg(AutoCAD file) import reports Tailormade is for Demo use only
    Symptom:
    When dwg files are imported to Prime Infrastructure, they report
    "For Demonstration Purposes only
    Tailor made software"
    Conditions:
    Prime Infrastructure - 2.0.0.0.294
    Use of dwg (Auto cad) files
    Workaround:
    None at this time
    Further Problem Description:
    CSCuj94500, Loading DWG floor maps on PI 2.0 appears in black background
    Symptom:
    On PI 2.0 when we try to import autoCAD .dwg file to map, the map appears in black background.
    Conditions:
    On PI 2.0 when we try to import autoCAD .dwg file to map
    Workaround:
    use 3rd party tool like Draftsight or AutoCAD Trueview to change the file to .jpg and import again to PI, after that the map appear in white background in PI 2.0.
    Further Problem Description:
    However, the same .dwg file when we imported it to PI 1.3 appear in map with white background.

  • ITunes 11 has black background with black text

    I had previously set iTunes to use the dark grid theme. Now I've upgraded to itunes 11 but i'm stuck with cases where I have a black background and black text with no preferences option to fix it. (the same problem I had with the previous itunes version, even when i tried selecting a different theme it wouldn't change)
    examples include the downloads window
    And views like album view that the text changes color based on the album art, and the background is supposed to too but mine doesn't, so sometimes the icons/text will be unreadable. Like the close, play, shuffle, etc buttons in the screen shot below.
    I have tried retinstalling iTunes several times between 10.6 and 11 to fix various bugs but it's never worked properly.
    Thanks for any help anyone can provide.

    Very Big thank you All of you for your help !!! It's been an hour that I didn't know what to do to see which songs to chooses because of the grey typo on black background !!! Merci
    En français : si vous visualisez les chansons d'itunes 11 en gris sur fond noir ou en noir sur fond noir et que itunes 11 est illisible donc, il faut simplement aller dans le terminal et coller cette ligne, cela réinitialisera les paramètres de contrastes d'itunes :
    defaults write com.apple.iTunes high-contrast-mode-enable -bool FALSE
    Enfin sauvée après une heure de galère à chercher partout comment changer la skin de itunes 11 alors que c'était en fait un bug d'affichage !!!

  • Imported .gif has black background

    Hello All,
    I imported a .gif with a transparent background but when I try to use the logo in cs4 premiere Pro it has a black background. I can't figure out how to take out the black background. Any help would be appreciated.
    Thank you
    -rico

    What you saw in my example was the Program Monitor expanded beyond the Frame Size of the Assets. If you are seeing black surrounding, then there is probably an issue between the Project/Sequence Preset and the actual source footage. Now, this might take a bit of interpolation, as there are some major changes between my PrPro 2.0, and CS4, but it should be similar enough that you can fill in the blanks, if I am clear enough. Or, it could just be a difference between the GUI in CS4 vs my PrPro 2.0.
    For me, Presets apply to entire Projects. For you, they can be applied to individual Sequences. If I need to find out what Preset was used (and any custom settings, should I have chosen Desktop), I would go to Project (in the Toolbar), and look at Project Settings. You should be able to do the same from the Sequence in the Toolbar. That should give you all of the settings. You can then Rt-click on your AV Asset and choose Properties. These should match in every respect.
    Now to the GIF. When you drag it to a Video Track, higher than your Video Clip, you still get that black background? This is not when used on a Title, but just as an Asset on the Timeline. Are there any Effects applied to the Logo?
    One more question: are you observing the display in the Program Monitor, and not in the Source Monitor. They look very similar, but are different displays. To get to the Program Monitor, if it is not Open, go to Window>Program Monitor. Note: it might be docked in a Pane, with other Monitors, or Panels, so you might need to find its tab, and click on that. To view in the Program Monitor, you will just drag the CTI (Current Time Indicator w/ the red Edit Line extending down from it) so that it is over both your GIF and also your Video Asset (on a lover Video Track). This will then display in the Program Monitor.
    I did not alter the GIF that you attached, in any way - no Scaling, no Effects, no Motion - just Import and drag into position. I am puzzled why this is not working exactly the same way for you.
    Now, Colin mentioned the Alpha Channel and its checkbox. Have you followed his directions there? I keep Use Alpha Channel checked, and had not even though about that.
    Good luck, and please let us know what you find out,
    Hunt

  • Transparent Flash has black background

    I have a video flash file created in Premiere Pro CS4 which I keyed out the background, exported as a FLV/F4V with an encoded alpha channel. I place the flash on a JPG in Dreamweaver CS4 and want the movie to run transparent, but I always get a black box surrounding my movie. I use the "wmode" as "transparent" in the flash dialog box, but this does not eliminate the black background around the movie. Any suggestions?

    Transparency with *.flv's works for me when I place the background on the bottom layer in the Flash program project (*.fla) and place the video on the layer above, in the Flash program project. Publish this "Flash Movie" from Flash and cut and paste the Flash code from the "Published" HTML page into either the table cell or div on your final Dreamweaver page depending upon whether you are building an "old school" table based page or a CSS based page.
    If you are creating one of those "floating" over the top, Web page movies, someone in the Flash or Dreamweaver forum should be able to help you with that.
    Also, in Premiere, you should be working in a "Desktop mode" sequence with "Square pixels" selected.
    Here are the settings to get the flv to encode with an alpha channel:

  • Change menus to black background and white text (not invert colors option)?

    I have an iPhone 5 on the way to me as I got one for a very good price. I am visually impaired. I currently have a Samsung Galaxy s3 which is crapping out on me after having it for a long time). One of the features I love about it is, the menus (settings, contacts, etc etc) are in high contrast (black background with white text, which is much easier on my eyes and easier to read. It is my understandiing that the iPhone is not the same way. I had a friend look on his, and the only option he found was the "Invert colors" option. The reason I don't want to use that is because it inverts ALL colors for everything on the phone, including pictures. t just want to invert the colors in all the menus so I can read them easier. Is there any way to do this? BTW it's running IOS 8.

    the invert colors option is the only way to achieve that on iPhone currently
    you should go to http://www.apple.com/feedback/ and request that feature added, I think a lot of people would use that

  • Image quality for background and screen saver

    Hi
    I have recently upgraded to Aperture 2.1. To take advantage of the additional/improved RAW image features, I have been migrating my older images from their original 1.1 RAW fine tuning to 2.0. However, after migrating most of my library (over 10k images) I have noticed that images using 2.0 have dramatically lost their sharpness when on the background & screen saver display. I have a 30" HD Apple Cinema Display, and the images look fine within Aperture itself. I've looked through the menus on System Preferences and Aperture Preferences but can't see anything obvious that would be causing this lack of quality.
    If anyone knows how to solve this I would be extremely grateful - I take a lot of photos, and usually have my most recent images on the screen saver as it helps me to evaluate them prior to culling!
    Kind Regards
    Vinny

    Hi Ian
    Thank you for the welcome and advice. I had a look in the preferences for Previews and the settings were not as high as they could be. I have adjusted them to the highest, and also unticked 'use camera jpeg when possible'. This has made a difference.
    Thanks again.
    Vinny

  • Saving image with transparent background for web/Dreamweaver

    How do I save a little image, so that the background stays transparent. I already have the image set up in Photoshop with a transparent background and have saved it as gif and png. When I import it into Dreamweaver the background stays white instead of transparent. What am I not doing right, since I read several posts saying that png and gif are the right formats to save in, if you want a transparent background?
    Thanks for any help with this,
    Anne

    Well now that you have told me to save with some sort of an alpha channel, it works perfectly.
    In CS5:
    Select layer,"Composition,Make movie". Then navigate to "Output module" and choose an option that has "alpha channel" in the title.Choose a name for your project "Output to". I now use "lossless alpha".I don't know if that is the best one, but it seems to be working fine.
    There is no "Quicktime" option in CS5 as in older versions of AE.
    I was trying to save as a video in general or for photoshop and that just wasn't working out well.
    I don't know what the "Frames to Layers import assistant" is that you mentioned though. I still tend to drag and drop, rather then import.
    Thanks for your help.

  • PDF has black background

    When I import a PDF, all of the text areas are black. Images are fine. Same with more than 75 PDF files. Perhaps I am doing something wrong?

    Please don't think my tardiness in answering is lack of interest. This is an on-going 'background' project here in the office as we attempt to post some PDFs.
    These are all taken from an 'ePaper' version of the newspaper where I write a weekly column. I wanted to make the columns available to people as PDFs, not as tiff, for all of the usual reasons. Should be simple, right?
    But this is proving to be more difficult than I imagined.
    I thought about converting to tiff and then using linked smaller images; people would click on the preview and download the pdf. But this can be onerous when you have a lot to do and a lot to keep doing. And it obviates the use of Aperture, which is how we handle all images; the workflow that I imagined involves adding the PDF files to Aperture each week, and then publishing to a gallery. Sweet.
    Not sure what direction to go now, though.
    Michael

Maybe you are looking for

  • Error message when closing down computer

    Adobe photoshop downloader boot will not shut down automatically when I close down the computer. What settings can I change. I cannot find anything to help in edit/preferences. I have the starter edition.

  • Our RMAN Catalog Problem

    Hello We have 7 major oracle instances on 2 servers and we have created a RMAN catalog on another server Our principal databases are Standard Oracle 10g (10.2.0.2.0) under linux , and the catalog is Enterprise Oracle 10g (10.2.0.2.0) in Windows all t

  • 'Please install a web browser' message

    I'm trying to see how badly the WebHelp function will mangle my Frame doc but can't get beyond this message when I try to compile. I have plenty of web browsers; how do I get RoboHelp to recognise them? Thanks, Simon

  • 2 iTunes librarys

    My old PC was hit by lightning and is out of comission. I can't get anything off it. I downloaded the latest version of iTunes to my new PC but when I hook the iPod up to it I get asked the following: iPod is synced w/ another iTunes library. Can onl

  • Maintain Aggregates-SQL Error

    Hi All, We are trying to create aggregates on a SALES overview cube 0SD_C03 on 0MATERIAL .We have some 100 million records in the cube. But it fails with an SQL Error. SQL Error: Arithmetic overflow error converting expression to data type int. Pleas