COMPGROUPS.NET   Search  Post Question   Groups  About  Contact  Register | Login

How to do image-type conversion Subscribe

I'd like to convert a standard TYPE_INT_ARGB BufferedImage to a
TYPE_BYTE_BINARY one. Getting simple black and white ARGB image from
original image was a piece of cake. However, I have no clue from there
on.

0
Reply HGA03630 11/17/2006 9:29:16 AM Header Report as Spam



hiwa wrote:
> I'd like to convert a standard TYPE_INT_ARGB BufferedImage to a
> TYPE_BYTE_BINARY one. Getting simple black and white ARGB image from
> original image was a piece of cake. However, I have no clue from there
> on.

You did not tell us what you want to achieve. So the following should
give you what you asked for, but it might not be what you really want:

BufferedImage argb = ...

BufferedImage bb = new BufferedImage(
argb.getWidth(),
argb.getHeight(),
TYPE_BYTE_BINARY);
Graphics2D g = bb.createGraphics();
bb.drawImage(argb, 0, 0, null);

Note: Not using an image observer can get you in trouble, e.g. if argb
is not completely loaded when you try to draw it on bb. But you get the
idea.

/Thomas
--
The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
0
Reply Thomas 11/17/2006 10:23:32 AM Header Report as Spam

Thomas Weidenfeller wrote:
> hiwa wrote:
> > I'd like to convert a standard TYPE_INT_ARGB BufferedImage to a
> > TYPE_BYTE_BINARY one. Getting simple black and white ARGB image from
> > original image was a piece of cake. However, I have no clue from there
> > on.
>
> You did not tell us what you want to achieve. So the following should
> give you what you asked for, but it might not be what you really want:
>
> BufferedImage argb = ...
>
> BufferedImage bb = new BufferedImage(
> argb.getWidth(),
> argb.getHeight(),
> TYPE_BYTE_BINARY);
> Graphics2D g = bb.createGraphics();
> bb.drawImage(argb, 0, 0, null);
>
> Note: Not using an image observer can get you in trouble, e.g. if argb
> is not completely loaded when you try to draw it on bb. But you get the
> idea.
>
> /Thomas
I tried that method first but what I got was a all black image --
darkness, darkness, be my pillow...
When I tried blue&white instead of black&white, what I got was a all
blue image -- deep deep sea all around us...
----------------------------------------
byte b = (byte)255;
icm = new IndexColorModel
(1, 2, new byte[]{0, b}, new byte[]{0, b}, new byte[] {b, b});
bw = new BufferedImage(scrw, scrh, TYPE_BYTE_BINARY, icm);
----------------------------------------

0
Reply hiwa 11/17/2006 11:35:34 AM Header Report as Spam

hiwa schrieb:
> Thomas Weidenfeller wrote:
>
>>hiwa wrote:
>>
>>>I'd like to convert a standard TYPE_INT_ARGB BufferedImage to a
>>>TYPE_BYTE_BINARY one. Getting simple black and white ARGB image from
>>>original image was a piece of cake. However, I have no clue from there
>>>on.
>>
>>You did not tell us what you want to achieve. So the following should
>>give you what you asked for, but it might not be what you really want:
>>
>> BufferedImage argb = ...
>>
>> BufferedImage bb = new BufferedImage(
>> argb.getWidth(),
>> argb.getHeight(),
>> TYPE_BYTE_BINARY);
>> Graphics2D g = bb.createGraphics();
>> bb.drawImage(argb, 0, 0, null);
>>
>>Note: Not using an image observer can get you in trouble, e.g. if argb
>>is not completely loaded when you try to draw it on bb. But you get the
>>idea.
>
> I tried that method first but what I got was a all black image --
> darkness, darkness, be my pillow...

It is because the renderer does no dithering.
In theory you might get dithering by inserting this line:
g.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
But in practice (in my Java 1.4.2 and 1.5.0) I get the same un-dithered
image as before. :-(

--
Thomas
0
Reply Thomas 11/17/2006 3:56:41 PM Header Report as Spam

Thomas Fritsch wrote:
> It is because the renderer does no dithering.
Sorry, it was my coding error. Correct code is:
----------------------------------------------------------------------
byte b = (byte)255;
icm = new IndexColorModel
(1, 2, new byte[]{b, 0}, new byte[]{b, 0}, new byte[] {b, b});//Blue
on White
bw = new BufferedImage(scrw, scrh, TYPE_BYTE_BINARY, icm);
----------------------------------------------------------------------
And, yes, it doesn't do dithering. Ugly image!

0
Reply hiwa 11/18/2006 1:01:00 AM Header Report as Spam

4 Replies
165 Views




Similiar Articles:
















5/16/2012 9:52:21 AM


Reply:
Alert me when someone responds to this posting.