Results 1 to 4 of 4
Thread: How save Image BMP Binary type?
- 11-17-2009, 03:44 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 2
- Rep Power
- 0
How save Image BMP Binary type?
Hello, I think a picture and saved in a BMP file with 24bit color, but it got the file size of 2Mb, I would save this file in binary format, because the color is only black and white.
This is possible?
I managed to do using only AWT, but as I use the IBM J9 must do the same but in SWT.
Could someone help me?
Thank you!
My Codes.
AWT
SWTJava Code:BufferedImage image= new BufferedImage(x, y, BufferedImage.TYPE_BYTE_BINARY); Graphics g = image.getGraphics(); g.setColor(Color.white); g.fillRect(0, 0, x, y); g.setColor(Color.black); g.drawString("TESTE DE IMPRESSAO", 20,20); ImageIO.write(image, "bmp", new File(file2));
Java Code:Image imagem = new Image(display, x, y); GC g = new GC(imagem); g.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); g.setForeground(display.getSystemColor(SWT.COLOR_BLACK)); g.setFont(new Font(Display.getDefault(), "DIALOG", font, SWT.NORMAL)); g.drawString("teste de impressap", 30, 30); g.dispose(); ImageData data=imagem.getImageData(); ImageLoader loader = new ImageLoader(); loader.data = new ImageData[]{imagem.getImageData()}; loader.save(file, SWT.IMAGE_BMP); imagem.dispose(); display.dispose();
- 12-21-2009, 06:40 PM #2
Hi,
you should manipulate the palette.
Try this one:
Note: that the platette data have to be in that order to achieve the white background. Play a little with the order and see what happens.
further look into eclipse.org/articles/Article-SWT-images/graphics-resources.htmlJava Code:public static void main(String[] args) { PaletteData palette = new PaletteData(new RGB[] { new RGB(255,255,255), new RGB(0,0,0) }); ImageData id = new ImageData(200, 200, 1, palette); Image imagem = new Image(Display.getCurrent(), id); GC g = new GC(imagem); g.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); g.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); g.setFont(new Font(Display.getDefault(), "DIALOG", 8, SWT.NORMAL)); g.drawString("teste de impressap", 30, 30); g.dispose(); ImageData data=imagem.getImageData(); ImageLoader loader = new ImageLoader(); loader.data = new ImageData[]{data}; loader.save("myBMP.bmp", SWT.IMAGE_BMP); imagem.dispose(); Display.getCurrent().dispose(); }
there is a chapter about saving images
- 12-22-2009, 01:14 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 2
- Rep Power
- 0
Hi, my code is:
Java Code:Display display = new Display(); int x = 384, y = 100; org.eclipse.swt.graphics.Color white = display.getSystemColor(SWT.COLOR_WHITE); org.eclipse.swt.graphics.Color black = display.getSystemColor(SWT.COLOR_BLACK); // Create a source ImageData of depth 1 (monochrome) PaletteData palette = new PaletteData(new RGB[]{white.getRGB(), black.getRGB(),}); ImageData sourceData = new ImageData(x, y, 1, palette); Image im = new Image(display, sourceData); GC gc = new GC(im); Font normal = new Font(Display.getDefault(), "DIALOG", font, SWT.NORMAL); Font bold = new Font(Display.getDefault(), "DIALOG", font, SWT.BOLD); gc.setFont(normal);
- 12-22-2009, 01:50 PM #4
Similar Threads
-
how to save image as jpg?
By katie in forum New To JavaReplies: 4Last Post: 04-15-2010, 10:07 AM -
How to set the background of binary image?
By hyz_zsu in forum Java 2DReplies: 1Last Post: 04-09-2009, 03:14 AM -
Save image as JPEG
By aartheesrini in forum Java AppletsReplies: 1Last Post: 03-16-2009, 05:56 AM -
how can i save an image from url
By happyday in forum Advanced JavaReplies: 2Last Post: 01-14-2009, 07:02 PM -
Save a jpg image on server
By yadavjpr in forum Java ServletReplies: 1Last Post: 11-21-2008, 01:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks