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);

Similar Messages

  • I am working in pages with a template and want to keep the image but get rid of the black background?

    I am working in pages with a template and want to keep the image but get rid of the black background?

    Surprise surprise but we can't see what you are looking at and referring to.
    What black background?
    If it is black background in the actual photo:
    Menu > Format > Instant Alpha > drag the cursor over the colored background you wish to remove
    Peter

  • 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.

  • How do I get rid of the black background in Facebook Photo Viewer?

    Pressing F5 works for Windows to remove the black background, but it doesn't work for Mac. Does anyone know how to get rid of it? Thanks!

    They are not "gray bars" that is the area off your page.
    Crop your view as Viking suggests.
    Peter

  • 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);

  • Exracting a transparent image from black background

    Hey all! A little bit confused on a project. I have an image that is semi-transparent. I am able to take the black out of the background around it, but am unsure about how to remove the acutal background from behind the image. I need to superimpose this image onto another-hence the background change. Any tips or ideas? I have the newest version of PS. Please help!
    Kind regards,
    Ashley

    Hi,
    I am moving your post to the Photoshop General Discussion forum. You should get a response there. (This forum is specifically for the Edit your first photo page.)
    Best regards,
    Randy Nielsen
    Product Integration Manager, Creative Cloud Learning & Training
    Adobe

  • How can I get rid of this black background on my firefox home page?

    yesterday the background on my firefox home page turned black. Where is the setting that will allow me to change it back to white?

    That may have been part of the SOPA protest on some sites yesterday.
    * http://en.wikipedia.org/wiki/Wikipedia:SOPA_initiative/Learn_more
    Reload web page(s) and bypass the cache.
    *Press and hold Shift and left-click the Reload button.
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Cmd + Shift + R" (MAC)

  • How do I get rid of a black background on ITunes Store page?

    My ITunes page is black and captions are obscure, eliminating any chance to browse.   How can I change the background back to the original?

    With that one, perhaps try Drgoo's suggestion from the following post:
    Re: Itunes Store - ALL Text Black/Cant See Anything

  • Getting rid of black background in iPhoto slideshow converted to .mov

    Hi all!
    I have a desperate friend who created about an hour long slide show in iPhoto using "Vintage Prints" theme --it has a black background with photos getting dropped in.  There are four segments she wants me to edit together for the whole show for her daughter's graduation party. Is there any way to get rid of that black background and replace it with a solid color background or texture?  I have tons of animated textures and backrounds but I can't figuere out how to bring them to the rescue since the .mov is already created......   I thought of keying but 'black' isn't the new chromakey blue or green......  thought of a garbage mask but the shapes of the photos and collages dropping in are not constant....  Ideas?
    I didn't see a way in iPhoto to convert that black background to white or color either.... Did I miss something there?
    Thanks all!
    ClemKins

    ClemKins wrote:
    ..  ...but I can't get a background or color in underneath....
    works like charme here:
    .. ok, needs some tweaking: a luma-key is never working as good as a color-key ... but iPhoto delivers some very solid black, so FCPX' keyer creates an acceptable job (in my humble criteria).
    ok, the fade-out-to-black in the ending of the slideshow theme makes a luma-key impossible!
    keep in mind: the 'key' is more like a 'key-hole' (=as a non-native speaker, this is my mnomic )  - the color, alpha or black gets transparent and allows a look-thru to anything underneath ... that simple.
    ClemKins wrote:
    ...this was so much easier in FC 7.  Thoughts?
    you still think in 'tracks' - no need
    Think of 'layers'

  • I want to use Get Panel Image in Labview 5.0.1 and need details on how to save the BMP data generated

    I am trying to generate an application that saves a copy of its front panel on completion. This is easy to do using an invoke node with Print VI to HTML but this does not work in an .exe format. I have seen elsewhere that you have to use the Get Panel Image method, but no details are supplied in LV 5.0.1 documentation of how to use the "image" data (1-D Unsigned Byte array) that is generated. I want to save this in a format that can then be read as a bitmap in any standard graphics package. Any assistance?

    Hi,
    If you'd upgrade to LV5.1 or 6 you could use the 'standard' vi's for this.
    You need a VI called "Write BMP File.vi". It's not shipped with LV5.0.1.
    This vi only uses 3 subVI's, so perhaps someone at NI can convert it and
    send it to you (sorry, I won't, it's copywrited).
    If you cannot get this VI anywhere, you'll need to figure out the BMP file
    format yourself. It's not too complicated, but still could take some days.
    Perhaps someone figured it out before LV5.1 was released.
    Regards,
    Wiebe.
    "RDK" wrote in message
    news:[email protected]..
    > I want to use Get Panel Image in Labview 5.0.1 and need details on how
    > to save the BMP data generated
    >
    > I am trying to generate an application that saves a copy
    of its front
    > panel on completion. This is easy to do using an invoke node with
    > Print VI to HTML but this does not work in an .exe format. I have seen
    > elsewhere that you have to use the Get Panel Image method, but no
    > details are supplied in LV 5.0.1 documentation of how to use the
    > "image" data (1-D Unsigned Byte array) that is generated. I want to
    > save this in a format that can then be read as a bitmap in any
    > standard graphics package. Any assistance?

  • Apple TV 2 Stuck on Black Background + Apple Logo

    My Apple TV 2 appears frozen when plugged in to the TV. When I restart (either through Remote or by unplugging the power cord)  it seems it's going to start up, but it just gets stuck on a black background with a silver Apple logo.
    I've tried plugging in the Apple TV to my computer using a micro-usb cable, but it doesn't show up on the iTunes list of devices.
    Any recommendations on how I could restore the device? The nearest Apple store is a couple of miles away and I wont be able to do the trip for a few days.
    Thanks.

    My ATV2 is also locked up in the same way :-(
    This all came about when I tried to run the latest update.
    I've tried plugging in JUST the micro USB cable so it's supposed to show up in iTunes but still nothing.
    Pressing the down arrow and Menu buttons on the remote (send ATV into DFU mode) hasn't worked either.
    Really don't what to do now except take it back to the store.
    Not happy.

  • How do you change the capture dimensions in the Get Panel Image VI

    My objective is to capture the front panel image to a JPEG file. I want to be able to alter the dimensions of Front Panel Image so I can exclude certain areas of the front panel. I am using the GET PANEL IMAGE.VI and the WRITE JPEG FILE.VI. I have tried using a Cluster structure from the bounds property of the GET PANEL IMAGE.VI to feed into the "rect" property of the WRITE JPEG FILE.vi however as soon as I alter the dimensions from the original dimensions it fails to save the panel image to file. Is this actually possible, or does LabVIEW restrict users from altering the panel capture dimensions? Or is this a known bug in LabVIEW v6.0?

    Hi,
    Here is a zip file containing two VIs.
    'Change Control Value.vi' when run will load the VI 'Demo.vi'. It will alter its size and the run demo.vi.
    On the front panel or demo.vi, press the Update button and the image will be written to c:\temp.
    All a bit crude but the mechanism works in labview 5.1.1. (Unfortunately I haven't got version 6.0.2 installed yet.)
    Regards
    Ray.
    Regards
    Ray Farmer
    Attachments:
    demo.zip ‏33 KB

  • Two Images in PDF (background image)

    Greetings
    Trying to replace an existing image in a report from filesystem and this replace an existing loaded image into the reports. This image should come as back of the photo for an ID Card. As it comes from the file system it pushs the photo in the background, which has to be in the foreground. So the filesystem image (pointing to a file in OS) in the background, the photo image from the database should sit on top of the OS image. This works fine earlier if the image is loaded into the report instead of file system.
    I am using 10g reports, any idea how will use the file system image in the background and push the photo image comes from the database on top of it.
    thanks

    Please ignore this thread. Has resolved. Removed both images and put the background image first and recreate the database image on top of file system image later, so it works now.
    The solution (just in case) is remove both images and recreate them in the order, i.e the background image first and the foreground image later.
    Cheers

  • WORD doc x files show lettering changed from black to white with black background, colors have black background

    WORD doc x files received open with black lettering changed to white with black backgrounds. Color images have black backgrounds. There is no issue for non MAC users. How can I open the document as sent? Thank you.

    Pages (any version) is not a word clone, and may not digest Word documents as accurately as their native Microsoft application. Pages v5 is also far from feature/functionality complete, and that only compounds this issue.
    Suggest you download/install the free LibreOffice and open the Word documents with it. Do the artifacts persist in LibreOffice?

  • Everytime i use firefox and open my facebook account, i'm always getting a black background when i open facebook picture, i need to click reload or refresh to view the pictures in normal setup. what do i need to do? please help

    when i always open my facebook pictures using mozilla firefox, the pictures always get a black background and i always need to reload the page to get the normal view of the pictures

    Clear the cache and the cookies from sites that cause problems.
    * "Clear the Cache": Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    * "Remove the Cookies" from sites causing problems: Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]

Maybe you are looking for

  • Weekly build notes listings

    Since there are major changes going on in the TLF weekly builds, and the ASDocs aren't up to date, and the changes made are not searchable, I thought people might want the list dumped on here so changes to particular classes would show up in a forum

  • User sip folder have many .cache files with 4kb and the folder is becoming full and Lync Client stops working

    User sip folder have manu Mailitem&username&.cache files until folder is full and Lync client stops working.

  • How to call a actionMethod from EL?

    Hi all, I have the following code <af:outputText value="#{bindings.getYCWarningMsg.execute}" id="ot35" partialTriggers="t1"/> getYCWarningMsg() is a method provided by AM, and will return a String which I want to display in the screen. How to invoke

  • It's not letting me reset my security questions

    I Am trying to buy a album but I can't because I dont member my security questiona and it doesn't let me reset them

  • Create New Instance.

    Hello Gurus, Can anybody tell me how to create new Oracle Instance, Currently I am having only one Oracle Instance i.e. RMIN1..Now I want to create another instance RMIN2 which should be connecting to same Database. I am using UNIX environment. Thanx