Convert a component to a BMP-file

Hello!
I�ve tried to convert my component where I have a chart drawn to a bmp-format file. I have picked part of the code from a Sun help page. This is how it looks:
//first my lines
Image image = component.createImage(component.getWidth(),
component.getHeight());
Graphics g = image.getGraphics();
Graphics2D g2d = (Graphics2D) g;
component.paint(g2d);
//then Suns lines
ParameterBlock pb = new ParameterBlock();
pb.add(image);
PlanarImage tPlanarImage =
(PlanarImage) JAI.create("awtImage", pb);
//Then, write out the PlanarImage (for example, in BMP format):
try {
OutputStream tOutput =
new FileOutputStream(fileName);
ImageEncoder tEncoder =
ImageCodec.createImageEncoder("BMP",tOutput,null);
tEncoder.encode(tPlanarImage);
tOutput.close();
catch (IOException ex) {
Error message is:
java.lang.RuntimeException: All samples must have the same size.
     at com.sun.media.jai.codecimpl.BMPImageEncoder.encode(BMPImageEncoder.java:134)
If some one could help me out I would be very grateful.
Best Regards
Staffan

Thanks for Your advice. I�ll then think I had to change to Java 5.0.
Best Regards
Staffan

Similar Messages

  • Comment convertir un .tiff en un .BMP?

    Bonjour à tous
    Comment convertir un .tiff en .bmp ???
    je sais ouvrir un .tiff avec Imaq mais pour le reste je sèche..

    You should be able to use the IMAQ Read File VI to read the file in, then use the Write BMP File VI to write the file. A similar approach is used in this example: Convert PNG or JPG to BMP file
    Cheers,
    Misha

  • How to convert a jpeg file into a 1-bit bmp file (2 colors image)

    Hi. I�m having serious problems to convert a jpeg file into a 1-bit bmp file (2 colors image).
    I�m using FileSaver.saveAsBmp(String t) but what i get is a bmp image, but with 16M colors, but what i want is a 2 colors bmp file. A black and white image.
    Does anybody know how to do this? I�m really getting crazy with ths problem.
    Thanks in advance

    Hi opalo,
    this code may help you...
    import java.awt.*;
    import java.io.*;
    import java.awt.image.*;
    import javax.imageio.ImageIO;
    class Write1 extends Component {
    //--- Private constants
    private final static int BITMAPFILEHEADER_SIZE = 14;
    private final static int BITMAPINFOHEADER_SIZE = 40;
    //--- Private variable declaration
    //--- Bitmap file header
    private byte bitmapFileHeader [] = new byte [14];
    private byte bfType [] = {'B', 'M'};
    private int bfSize = 0;
    private int bfReserved1 = 0;
    private int bfReserved2 = 0;
    private int bfOffBits = BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE;
    //--- Bitmap info header
    private byte bitmapInfoHeader [] = new byte [40];
    private int biSize = BITMAPINFOHEADER_SIZE;
    private int biWidth = 50;
    private int biHeight = 70;
    private int biPlanes = 1;
    //private int biBitCount = 24;
    private int biBitCount = 1;
    private int biCompression = 0;
    private int biSizeImage = 0x030000;
    private int biXPelsPerMeter = 0x0;
    private int biYPelsPerMeter = 0x0;
    private int biClrUsed = 0;
    private int biClrImportant = 0;
    //--- Bitmap raw data
    private int bitmap [];
    //--- File section
    private FileOutputStream fo;
    //--- Default constructor
    public Write1() {
    public void saveBitmap (String parFilename, Image parImage, int
    parWidth, int parHeight) {
    try {
    fo = new FileOutputStream (parFilename);
    save (parImage, parWidth, parHeight);
    fo.close ();
    catch (Exception saveEx) {
    saveEx.printStackTrace ();
    * The saveMethod is the main method of the process. This method
    * will call the convertImage method to convert the memory image to
    * a byte array; method writeBitmapFileHeader creates and writes
    * the bitmap file header; writeBitmapInfoHeader creates the
    * information header; and writeBitmap writes the image.
    private void save (Image parImage, int parWidth, int parHeight) {
    try {
    convertImage (parImage, parWidth, parHeight);
    writeBitmapFileHeader ();
    writeBitmapInfoHeader ();
    writeBitmap ();
    catch (Exception saveEx) {
    saveEx.printStackTrace ();
    * convertImage converts the memory image to the bitmap format (BRG).
    * It also computes some information for the bitmap info header.
    private boolean convertImage (Image parImage, int parWidth, int parHeight) {
    int pad;
    bitmap = new int [parWidth * parHeight];
    PixelGrabber pg = new PixelGrabber (parImage, 0, 0, parWidth, parHeight,
    bitmap, 0, parWidth);
    try {
    pg.grabPixels ();
    catch (InterruptedException e) {
    e.printStackTrace ();
    return (false);
    pad = (4 - ((parWidth * 3) % 4)) * parHeight;
    biSizeImage = ((parWidth * parHeight) * 3) + pad;
    bfSize = biSizeImage + BITMAPFILEHEADER_SIZE +
    BITMAPINFOHEADER_SIZE;
    biWidth = parWidth;
    biHeight = parHeight;
    return (true);
    * writeBitmap converts the image returned from the pixel grabber to
    * the format required. Remember: scan lines are inverted in
    * a bitmap file!
    * Each scan line must be padded to an even 4-byte boundary.
    private void writeBitmap () {
    int size;
    int value;
    int j;
    int i;
    int rowCount;
    int rowIndex;
    int lastRowIndex;
    int pad;
    int padCount;
    byte rgb [] = new byte [3];
    size = (biWidth * biHeight) - 1;
    pad = 4 - ((biWidth * 3) % 4);
    if (pad == 4) // <==== Bug correction
    pad = 0; // <==== Bug correction
    rowCount = 1;
    padCount = 0;
    rowIndex = size - biWidth;
    lastRowIndex = rowIndex;
    try {
    for (j = 0; j < size; j++) {
    value = bitmap [rowIndex];
    rgb [0] = (byte) (value & 0xFF);
    rgb [1] = (byte) ((value >> 8) & 0xFF);
    rgb [2] = (byte) ((value >> 16) & 0xFF);
    fo.write (rgb);
    if (rowCount == biWidth) {
    padCount += pad;
    for (i = 1; i <= pad; i++) {
    fo.write (0x00);
    int b = 1200;
    fo.write(b);
    rowCount = 1;
    rowIndex = lastRowIndex - biWidth;
    lastRowIndex = rowIndex;
    else
    rowCount++;
    rowIndex++;
    //--- Update the size of the file
    bfSize += padCount - pad;
    biSizeImage += padCount - pad;
    catch (Exception wb) {
    wb.printStackTrace ();
    * writeBitmapFileHeader writes the bitmap file header to the file.
    private void writeBitmapFileHeader () {
    try {
    fo.write (bfType);
    fo.write (intToDWord (bfSize));
    fo.write (intToWord (bfReserved1));
    fo.write (intToWord (bfReserved2));
    fo.write (intToDWord (bfOffBits));
    catch (Exception wbfh) {
    wbfh.printStackTrace ();
    * writeBitmapInfoHeader writes the bitmap information header
    * to the file.
    private void writeBitmapInfoHeader () {
    try {
    fo.write (intToDWord (biSize));
    fo.write (intToDWord (biWidth));
    fo.write (intToDWord (biHeight));
    fo.write (intToWord (biPlanes));
    fo.write (intToWord (biBitCount));
    fo.write (intToDWord (biCompression));
    fo.write (intToDWord (biSizeImage));
    fo.write (intToDWord (biXPelsPerMeter));
    fo.write (intToDWord (biYPelsPerMeter));
    fo.write (intToDWord (biClrUsed));
    fo.write (intToDWord (biClrImportant));
    // DataOutputStream temp = new DataOutputStream(fo);
    // int m = 32;
    // temp.writeInt(m);
    catch (Exception wbih) {
    wbih.printStackTrace ();
    * intToWord converts an int to a word, where the return
    * value is stored in a 2-byte array.
    private byte [] intToWord (int parValue) {
    byte retValue [] = new byte [2];
    retValue [0] = (byte) (parValue & 0x00FF);
    retValue [1] = (byte) ((parValue >> 8) & 0x00FF);
    return (retValue);
    * intToDWord converts an int to a double word, where the return
    * value is stored in a 4-byte array.
    private byte [] intToDWord (int parValue) {
    byte retValue [] = new byte [4];
    retValue [0] = (byte) (parValue & 0x00FF);
    retValue [1] = (byte) ((parValue >> 8) & 0x000000FF);
    retValue [2] = (byte) ((parValue >> 16) & 0x000000FF);
    retValue [3] = (byte) ((parValue >> 24) & 0x000000FF);
    return (retValue);
    class Writebmp
         public static void main(String args[])
              //Image img = Toolkit.getDefaultToolkit().getImage("jatin.bmp");
              try
              File filename = new File("jatin_test.bmp");
              BufferedImage image = ImageIO.read(filename);
              Graphics graphics = image.getGraphics();
              graphics.drawString("&#2313;&#2332;&#2327;&#2352;",10,30);
              Write1 w = new Write1();
              Image img = Toolkit.getDefaultToolkit().getImage("jatin_test.bmp");
              w.saveBitmap("jatin_test.bmp",img,200,200);
              catch (IOException e)
    System.err.println ("Unable to write to file");
    System.exit(-1);
    }

  • Converting multiple bmp files to PDF using acrobat 7.0 from DOS prompt

    Hi,
    I have a requirement to convert multiple BMP files in a folder to one PDF.
    I can use multiple file conversion option in acrobat to combine and convert them to one PDF .. but I have 2000 such folder to conver to PDF.
    PDF should be name after the folder name.
    Is there a to automate this in acrobat.. or can we run this conversion from DOS prompt using commands.. so that I can create a bat file and have them converted. Pls let me know.
    Thanks
    Pugazh

    I have not tried BMP files, but do JPeg, GIF, TIFF, and PNG files regularly. I simply open Acrobat, then select the graphics files in explorer and drag & drop to Acrobat. I then organize the graphics if needed (using the pages tab) and save to a PDF.

  • How to batch convert bmp files into jpg by dos command or c# program language?

    How to batch convert bmp files into jpg by dos command or c# program language?
    Many thanks for replying.

    Try
    GraphicsMagick.

  • Converting .bin (Binary) File to .bmp ( BMP ) File

    Hi All,
    I have a requirement to convert .bin file to .bmp file. The binary file is generated by the video frames and now i want to convert this binary file into the .bmp file. Can anybody help me how to do this and if possible then pls write the sample code.
    -Thanks

    How do you meen generated by the video frames?
    Do you mean that the .bin file is created by an application in the event of a screen shot fo example?
    If so then the big question is in what format did this application save the image data
    Please elaborate.
    Don't bank on the idea of us giving you code,
    we will if possible point you into the right direction and help where required but thats about as far as we prefer to go.

  • Converting bmp file to pdf

    Hi all,
    Please help me to solve this:
    1) convert bmp file to PDF( using FM) .
    2)There can be many such bmp files ..append them to single pdf file after converting them.
    Thanks and Regards,
    KC

    As has been discussed many times here before, you can't really merge PDF files programmatically in ABAP after they have been created.  Your best bet with this 'unique' requirement is to use a form-based approach I think.
    With a smartform one approach is to create a single page with a window with a graphics node (dynamic name) in it, with the bitmap name specified in the form interface.  Unless you have already loaded the bitmaps in the graphics manager (SE78), you would load the bitmaps at runtime from the presentation server or the application server and then create the graphics dynamically using the methods of class CL_BDS_DOCUMENT_SET prior to calling the form for each bitmap (a topic discussed recently in the ABAP forums or you can view how SE78 does it by checking the code).  Create a merged spool and then use the standard function to convert the OTF data to PDF format.
    A similar approach can be used with Adobe forms, but you would need to load the bitmaps to the web repository, not the graphics manager.
    What exactly is in the bmp files and where are they stored?  Are they form templates?  You may get a better answer with more details.

  • How to converting a flash clip into a bmp file quickly

    Hi,
    I’d like to get help on converting a flash clip into a
    bmp file. I have an application developed with ActiveX technology.
    There is a flash control embedded in the ActiveX control, which has
    a printing button. The end users can press the printing button to
    print the flash picture as well as other text content.
    I get the flash picture for printing in follow steps:
    1.Create a BitmapData object
    var bmp:BitmapData = new BitmapData(w, h, false);
    2.Obtain the image of current flash
    bmp.draw(mc, mc.transform.matrix, new ColorTransform(), 1,
    new Rectangle(x, y, w, h));
    3.Get pixels of flash image one by one in loop, and save them
    into a PixelCollection
    bmp.getPixel(col, row);
    4.Move the PixelCollection into flash container
    fscommand("print", load_PixelCollection);
    5.Ocx control gets the PixelCollection and converts it into
    BMP format
    But I find it is very slow when action script gets pixels one
    by one. Getting pixels of a middle size flash may spend one minute.
    It is hard for our customer to stand. Does anyone have idea to get
    the flash image quickly? 
    Any help is appreciated.
    Shi Hang

    What about the built-in print methods, wouldn't it be better
    to use those here?
    Getting all pixel values is a time intensive process, because
    of the amount of pixels. It may be a bit faster if you split the
    getPixel() loop over some frames, but I'm not exactly sure how to
    do that (just read it somewhere).
    If the content is fixed, you could create the pixel array in
    the background while the user looks at it. This is quite some
    overhead, but when the user decides to print, the array would
    already be there.
    Finally, not helpful here, but interesting:
    quote:
    BitmapData.getPixels()
    No longer do you have to loop through every pixel in a
    bitmap, one at a time with getPixel to send a bitmap to the server.
    This method returns a ByteArray containing the hexadecimal color
    value of each of the pixels in the specified rectangular region of
    a bitmap. Use this method in conjunction with the new ZLib
    compression method; ByteArray.compress() to compress and send a
    bitmap over the wire to a server so it can be converted into a file
    ready for downloading.
    (from
    http://www.flashguru.co.uk/actionscript-3-new-capabilities/)
    This will be available in AS 3.
    hth,
    blemmo

  • Convert a jpeg file into a 1-bit bmp file (2 colors image).

    Hi. I�m having serious problems to convert a jpeg file into a 1-bit bmp file (2 colors image).
    First, i,ve tried to get a 1-bit jpeg. But i think this is not possible, so what i have to do is to get a 1-bit bpm file.
    I�m using FileSaver.saveAsBmp(String destination) and what i get is a bmp image, but with 16M colors, but what i want is a 2 colors bmp file. A black and white image.
    Does anybody know how to do this? I�m really getting crazy with ths problem.
    Thanks in advance

    You better read this at
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=733738

  • Converting Picture to *.bmp file

    Hi,
    With the excellent pictures/ graphs that LabVIEW is able to produce, I
    haven't been able to convert a picture (blue squiggly line datatype!) to a
    pixmap or flattened pixmap for the purpose of saving as a JPEG/BMP file.
    Can this be done? If so please let me know.
    Regards,
    Paul Conroy
    TIP-CSIRO
    Sydney, Australia
    [email protected]

    I've come across the same problem you have, and the only (altough not very nice solution) is to write a subvi with the picture as input (and only the picture visable on the front panel!), set the picture draw area to show the entire picture and next use the invoke node "Get panel image" with only visable area set to "False". This creates a flattened pixmap wich you can use as input for the write to *.jpg, *.png or *.bmp vi's.
    There is however one catch. The front panel has to be activated (shown) for a brief period of time, since otherwise the picture won't redraw the data. The size of the front panel is however not important, so I briefly open the front panel in a very tiny format somewhere at the bottom of the screen, so the user never notices that the screen was brie
    fly active.
    I know this method is not very nice, but since there seems to be no other way to convert the picture to flattened data it is (for now) the only solution I can think of.
    I hope I've helped you with this information,
    Marcel Kalf.

  • Creating pie chart diagram in java  and converting into BMP file

    hi all ,
    my req. is to create draw a pie chart diagram and store
    the picture in BMP. it is Possible. if so how ?
    cheers
    senthil

    Hi Senthil,
    This response is a bit late but I hope it can help in some way.  Your requirement (to create draw a pie chart diagram and store the picture in BMP) is possible and actually quite easy if you don't mind using two open source libraries.  In his previous response to this thread, Detlev mentioned JFreeChart for as a solution for charting however he also mentioned that it lacks support for BMP.  Although this is true, you can use the JFreeChart library (http://www.jfree.org/jfreechart/index.html) in conjunction with an imaging library to meet your requirement.  I have used JFreeChart on multiple projects and I highly recommend it.  For the imaging library you have many options, however the only one I have used is The Java Imaging Utilities (JIU - http://jiu.sourceforge.net/).  Using these two class libraries, you can generate your pie chart and save it to a BMP file with the following block of code:
         try
             JFreeChart chart = this.createChart();
             FileOutputStream streamOut = new FileOutputStream("your/files/path/BMPfile.bmp");
             BufferedImage image = chart.createBufferedImage(600, 300);
             if(image == null)
                  reportError("Chart Image is NULL!!!!!!!!");
                  return(false);
             RGB24Image rgbImage = ImageCreator.convertImageToRGB24Image(image);
             Codec codec = new BMPCodec();
             codec.setImage(rgbImage);
             codec.setOutputStream(streamOut);
             codec.process();
             codec.close();
             streamOut.flush();
             streamOut.close();
        }catch(IOException ioExcept)
             // throw or handle IOException...
             return(false);
        }catch(OperationFailedException opFailedExcept)
             // throw or handle OperationFailedException...
             return(false);
    The first line inside the catch block calls a helper method that should create the actual chart using the JFreeChart library.  Once you have your chart instance (all chart types are represented using the JFreeChart class), you can then retrieve a BufferedImage of the chart (JFreeChart.createBufferedImage(int width, int height);).  In our situation, the BufferedImage class will act as an "intermediate" class, for both libraries (the charting and imaging) can make sense of BufferedImages.  The rest of the code deals with storing the generated chart (the BufferedImage) as a BMP file to disk.  The RGB24Image, Codec, BMPCodec, CodecMode, and OperationFailedException classes are all part of the JIU library.  Also, note that the storage  source is not solely limited to a File on disk; the Codec.setOutputStream(OutputStream os) method will accept any subclass of OutputStream.  This implies that not only can you store to the actual App Server disk (where your app is running) but also to sources such as Knowledge Management (KM) resources or even directly to the clients browser (in the case of an iView). 
    Once again, sorry for the late response and let me know if you have any questions regarding the code above. 
    Regards,
    Michael Portner

  • .bmp files do not show as icons in the event library - I am having to convert them to .jpg  to achieve a display

    Although .bmp files are to some extent supported, I find that on importing them they do not show as icons in the event library. I am having to convernt them to .jpg files to produce this result.   Am I doing something wrongly, or is this the experience of others as well?

    Yes - I've posted one of the files to Dropbox and it appears perfectly in picture form on my IPad.   So it seems there is nothing wrong with the files.  I'm even more puzzled now!  I'll try to upload a smaller (less than 2mb) file here.  The files I am using in the project, which is a kind of family history using stills,  are a complete mix of types - tif, jpg, Canon raw(cr2), psd and bmp.   Some, including, I suspect, many of the .bmps are scans from old prints, as this one.

  • Issue in creating bmp file with cl_igs_chart_engine class

    Hi All,
    I want to populate dynamic graphic in a smartform.
    Im using cl_igs_chart_engine class to produce a GIF format of a chart.
    Then im trying to use class cl_igs_image_converter to convert that gif into a bmp format using INPUT = 'image/gif' and OUTPUT = 'image/x-ms-bmp'.
    but it returns with system failure exception  in
    call function 'PIGFARMDATA' .
    There is no error happening in case of converting any graphic format(bmp,tiff) to gif format but system failure exception occurs while trying to convert into bmp format.
    Appreciate your inputs.
    Cheers,
    Vikram

    Hi,
    I have taken a copy of program GRAPHICS_IGS_CE_TEST and made changes in it. In std program, file type in customizing XML is 'PNJ'. I changed it to 'BMP' as per your suggestion. However, in the
    call method l_igs_ce->execute
          exceptions
          others = 1.
    there is a call function for 'PIGFARMDATA'. Im getting exception error( sy-subrc = 2) for system failure.
    This program works fine if the file type in customizing XML is 'GIF' or 'PNG' but not for 'BMP' file types.
    Please advice.
    Cheers,
    Vikram

  • How to open a BMP file in a JLabel???

    Hi all,
    My problem is that I want to set a BMP file as icon of a JLabel, but the Class ImageIcon doesn't support BMP files.
    Thank you all.
    Marco Aur�lio
    from Brazil
    we'll win the FIFA World Cup!!

    The easiest way to do that is to get a graphics package that can convert a BMP file to a JPG file. Some versions of Microsoft Paint will do that, but you should be able to find another one if you need it.
    I hope Brazil wins, but if they don't it will be because the referees give it to Korea.

  • Error while uploading *.BMP file using SE78

    Hi
    I am trying to upload a BMAP file from presentation server onto the document server using SE78.
    I am facing an error saying
    "This is not a *.BMP file(they begin with <> "BM")"
    Message no. TD874
    I have the necessary company logo in this file and I want to put this in the sapscript.
    Is there some formatting that needs to be done to the bitmap file before importing in SE78.
    Please help!
    Thanks
    Bala

    hi
    Convert BMP from <b>Command prompt using ren command</b>
    then follow below process
    Go to transaction SE78.
    Follow the path given below (on the left windows box) :-
    SAPSCRIPT GRAPHICS --> STORED ON DOCUMENT SERVER --> GRAPHICS --> BMAP
    Enter the name of the graphics file on the right side and Go to the menu GRAPHIC --> IMPORT
    The program is RSTXLDMC, the logo needs to be save in .TIF format.
    Use transaction SE78 to inmport graphics to SAP.
    In the form painter, you can either include directly to the form using menu Edit->Graphic->Create or using the INCLUDE statement in a window.
    To use an INCLUDE stanment, goto into the woindow script editor and use menu Include->Graphic. The include can look like this for a bitmap:
    /: BITMAP MYLOGO OBJECT GRAPHICS ID BMAP TYPE BMON
    regards
    vinod

Maybe you are looking for

  • Is there an easy way to create breadcrumbs in Muse?

    I'm creating a new site and I want to add some breadcrumb navigation links, in addition to using the Menu Bar widget. Is there an easy way to build breadcrumb links? Or do I just create them manually?

  • Fixed number of rows in ADF table

    Can we specify fixed number of rows for ADF table so even no rows displayed it will still show 10 empty rows.

  • More XI 3.0-- IDoc-- R/3 - Trouble

    hi, i was trying to set up a scenario in which an idoc matmas04 is sent via XI to the receiver-R/3 instead of pure ALE/IDoc transfer. I get the corresponding Error in the XI-Monitoring: translated to English it says something like: Receiver Service c

  • App that could do a hot key and leave clipboard

    Is there an app that can do a hotkey but leave the clipboard alone? I love drag thing, but when I use it for hotkeys I get in trouble. I put some important text on the clipboard. Then I get distracted and compose an email. In the subject line I hotke

  • Safari dock icon menu commands

    hi there i've searched through the forums and tried the recommended actions (re-install OS X, delete and re-install safari and remove the plist) but i'm still getting the following problem on my wife's macbook... the new window and the window select