Bitmap Alpha Problem

Hi;
I'm trying to tweak a script I found online to work for my application.  The problem I am having is to make a certain part of the bitmap that is  created by code transparent...but only a certain part of it. The code  has the following:
_fire = new BitmapData(865, 92, false, 0xffffff);
Note
the alpha flag must be set to false, which is the source of my problem,
or nothing prints to screen at all. I need to make certain pixels
transparent. _fire is added to the stage and then called thus:
_fire.paletteMap(_grey, _grey.rect, ZERO_POINT, _redArray, _greenArray, _blueArray, _alphaArray);
at the end of the script. The colors for the arrays are created thusly:
private function _createPalette(idx:int):void {
_redArray = [];
_greenArray = [];
_blueArray = [];
_alphaArray = [];
for (var i:int = 0; i < 256; i++) {
var gp:int = new int();
gp = _fireColor.getPixel(i, 0);
if (gp < 1050112)
_redArray.push(255);
_alphaArray.push(255);
} else {
_redArray.push(gp);
_alphaArray.push(0);
_greenArray.push(0);
_blueArray.push(0);
I
added that if clause to capture when the color is black because that's
where I need to make it transparent. The problem is that where I need it
to be transparent, it's blue (why blue I don't know). Is there any way
to make it transparent? The entire code follows.
TIA,
George
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.ColorMatrixFilter;
import flash.filters.ConvolutionFilter;
import flash.geom.ColorTransform;
import flash.geom.Point;
import flash.system.LoaderContext;
import flash.net.SharedObject;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
[SWF(width=465, height=92, backgroundColor=0xffffff, frameRate=30)]
public class Fire extends Sprite {
private static const ZERO_POINT:Point = new Point();
private var _fireColor:BitmapData;
private var _currentFireColor:int;
private var _canvas:Sprite;
private var _grey:BitmapData;
private var _spread:ConvolutionFilter;
private var _cooling:BitmapData;
private var _color:ColorMatrixFilter;
private var _offset:Array;
private var _fire:BitmapData;
private var _redArray:Array;
private var _zeroArray:Array;
private var _greenArray:Array;
private var _blueArray:Array;
private var _alphaArray:Array;
public function Fire() {
//            stage.scaleMode = StageScaleMode.NO_SCALE;
//            stage.quality = StageQuality.LOW;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO  MPLETE, _onLoaded);
loader.load(new URLRequest('images/fire-color.png'), new LoaderContext(true));
private function _onLoaded(e:Event):void {
_fireColor = Bitmap(LoaderInfo(e.target).loader.content).bitmap  Data;
_canvas = new Sprite();
_canvas.graphics.beginFill(0xffffff, 0);
_canvas.graphics.drawRect(0, 0, 865, 465);
_canvas.graphics.endFill();
_canvas.addChild(_createEmitter());
_grey = new BitmapData(865, 465, false, 0xffffff);
_spread = new ConvolutionFilter(3, 3, [0, 1, 0,  1, 1, 1,  0, 1, 0], 5);
_cooling = new BitmapData(865, 465, false, 0xffffff);
_offset = [new Point(), new Point()];
_fire = new BitmapData(865, 92, false, 0xffffff);
addChild(new Bitmap(_fire));
_createCooling(0.16);
_createPalette(_currentFireColor = 0);
addEventListener(Event.ENTER_FRAME, _update);
//            stage.addEventListener(MouseEvent.CLICK, _onClick);
private function _onClick(e:MouseEvent):void {
if (++_currentFireColor == int(_fireColor.height / 32)) {
_currentFireColor = 0;
_createPalette(_currentFireColor);
private function _createEmitter()isplayObject {
var tf:TextField = new TextField();
tf.selectable = false;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.defaultTextFormat = new TextFormat('Verdana', 80, 0xffffff, true);
tf.text = '__________________________________________';
tf.x = (465 - tf.width) / 2;
tf.y = 0;
//            tf.y = (465 - tf.height) / 2;
return tf;
private function _createCooling(a:Number):void {
_color = new ColorMatrixFilter([
a, 0, 0, 0, 0,
0, a, 0, 0, 0,
0, 0, a, 0, 0,
0, 0, 0, 1, 0
private function _createPalette(idx:int):void {
_redArray = [];
_greenArray = [];
_blueArray = [];
_alphaArray = [];
for (var i:int = 0; i < 256; i++) {
var gp:int = new int();
gp = _fireColor.getPixel(i, 0);
if (gp < 1050112)
_redArray.push(255);
_alphaArray.push(255);
_greenArray.push(255);
_blueArray.push(255);
} else {
_redArray.push(gp);
_alphaArray.push(0);
_greenArray.push(0);
_blueArray.push(0);
private function _update(e:Event):void {
_grey.draw(_canvas);
_grey.applyFilter(_grey, _grey.rect, ZERO_POINT, _spread);
_cooling.perlinNoise(50, 50, 2, 982374, false, false, 0, true, _offset);
_offset[0].x += 2.0;
_offset[1].y += 2.0;
_cooling.applyFilter(_cooling, _cooling.rect, ZERO_POINT, _color);
_grey.draw(_cooling, null, null, BlendMode.SUBTRACT);
_grey.scroll(0, -3);
_fire.paletteMap(_grey, _grey.rect, ZERO_POINT, _redArray, _greenArray, _blueArray, _alphaArray);

I am importing it into another *.as file:
    import Fire;
       var myFire:Fire = new Fire();
           addChild(myFire);
TIA,
beno

Similar Messages

  • Pre multiplied alpha problem

    Hello,
    I am making a drawing app. In it I am using a feathered brush ( ie a gradient with 0 alpha on edges). I copypixel from this brush bitmap to my canvas on every mouse move. Problem with this is that color on the edges is different than that on the center. I read on internet that it is because flash uses pre-multiplied alpha in bitmapdata.
    Is there a way to solve this problem. Can I turn off the pre-multiplexing of alpha with base color? Please help
    Thanks

    No that is not the problem. Problem is not about alpha getting darker, Its that when flash pre multiply alpha with RGB it changes the value of RGB, it changes the orignal color hence making a great data loss.
    for example
    var map:BitmapData = new BitmapData(1,1,true,0xffffffff);
    map.setPixel32(0,0,0x00ffffff); // RGBA(255, 255, 255, 0);
    trace( map.getPixel32(0,0).toString(16)) // traces 0x00000000
    map.setPixel32(0,0,0x20fcfcfc);
    trace( map.getPixel32(0,0).toString(16)) // traces 0x20ffffff
    When I draw a yellow gradient circle on bitmapdata with 0 alpha outside and then copypixels of that bitmapdata to other bitmapdata the edges become green, because flash had pre multipled the yellow with alpha and change its orignal RGB
    values.
    you can see result here
    Edit: Take color values like this:
    1) A yellow that is slightly towards green like: 0xf5ff00 then it will round it to green
    2) A yellow that is slightly towards red like: 0xffec00 then it will round it to red.
    3) A perfect yellow 0xFFFF00 then it wont round it to anything and you will get the desired result

  • Selecting Embedded Bitmap Text - Problem

    I tried to create a Flash TextField, containing Text with
    maximum sharpness.
    So i embedded Verdana Font Size 8 as Bitmap Text, and set
    sharpness and thickness to my benefits.
    Now the Text ist displayed cleary, but if you try to select
    or write into the text box it really suxs:
    The Cursor position gets a higher distance to the text while
    the text line gets larger.
    Anyone know this problem, i searched this forum but i didnt
    find a solution about this prob.

    I assume you opened a new Gateway session after you have added that parameter and that you see it in the trace file....
    There's a trial ODBC driver from DataDirect (www.datadirect.com) available for download and which you can test. Check if that driver works. If yes, make sure you have the latest ODBC driver release applied to your env that matches your configuration and if needed ask the ODBC vendor for help.
    - Klaus

  • Intersecting Layers with alpha problem

    Hi,
    I have a problem with Motion when two layers intersect. On layer is totally opaque, and the second layer has transparent areas. The problem occurs in areas when the transparent areas intersect with opaque areas. In those regions I get a dark gray line appearing.
    Check out this image and you will see what I mean.
    http://jack.fxhome.com/MotionLine.jpg
    Note: I get this unwanted line in the exported frame as well.
    Why does motion do this?
    Is there anyway around this?
    Thanks

    1) Try setting your Render Quality to Best (under the View pop-up menu)
    2) Try changing the alpha interpretation of the layer with transparency - select it, press Shift-F, and try the different options in the Inspector's Media tab.

  • Freeze frame with Alpha problem.

    I have exported a 3 second graphic with alpha channel from After Effects.
    It keys perfectly until I drop on a freeze frame to lengthen it.
    There is a luminance drop of about 5% between the AE clip and the freeze
    of that clip. The freeze still maintains the alpha but you can see the change in luminance as soon as you apply the freeze to the clip.
    I have trashed prefs already but to no avail.
    Working in 8 bit uncompressed with a AJA Kona LHe card
    Any ideas how to rectify this??

    OK, here is the solution. Working in 8 bit, my video processing
    was selected to be 'Render in 8 bit YUV' which seems sensible.
    The problem with the freeze frames disappears when I select
    'Render all YUV material in high precision YUV'
    So now we know!! Thanks for the help and advice.

  • Sound Blaster Tactic3d alpha problems

    Hi, i have some problems with installing Sound Blaster Tactic3d alpha drivers.
    First is that i don't have pannel after installing drivers and second one is that my microphone is muted. Can someone help me ?
    *EDIT*
    Problems fixed (downloaded and installed this : http://www.userdrivers.com/Sound-Card/Creative-Sound-Blaster-Tactic3D-Alpha-Pack--0-000-for-Windo... ), but now control pannel is freezing on pop up.

    Hi,
    This could be caused by residual files from previous installation. It would advisable to uninstall and reinstall the package with a clean boot of your system. This article may help.

  • Bitmap animation problem

    I made an animation with a collection of bitmaps from
    fireworks. I wanted to use it in the "over" state of a button, but
    when I go to swap, all it give me is access to is the 8 bitmaps I
    imported, not the animation/movie clip I want as the over state. Is
    it possible to do what I'm trying to do?

    swap is only for symbol instances.
    ~~~~~~~~~~~~~~~~
    --> Adobe Certified Expert
    --> www.mudbubble.com
    --> www.keyframer.com
    ~~~~~~~~~~~~~~~~
    Sly1211 wrote:
    > I think you gave me my answer. What I was trying to do
    was sawp using a static
    > bitmap rom my animation. Following your advice, I made a
    movie new clip
    > (flash) and swaped in my animation & it worked. The
    animation was off to the
    > side when I rolled over the button, but that I think
    will be an easy fix sice I
    > was just doing it qucik & didn't have the new movie
    clip the correct size.
    > Thanks for your help & I like your web site.
    >

  • Alpha problem in Flash

    I lately generated a single color wireframe graphic in
    Illustrator, and saved this as .png format, set the background as
    transparent, I imported it into Flash library as graphic symbol,
    and drag it onto the stage, but the alpha channel was completely
    disable, I couldn't apply transparency onto the wireframe object, I
    wonder why?

    I haven't seen this come up before, but usually this forum deals with end user issues.  I'd recommend hoping over to bugbase.adobe.com and entering a bug.  We'll take a look and let you know what we find.
    Thanks,
    Chris

  • Java3D Alpha Problem

    Hello,
    I have a PositionInterpolator with an Alpha. I need to alter the Increasing- and/or Decreasing-Time of the Alpha-Object while the scene is running. When I do it, the value of my Alpha-Object alters nearly unpredictable... I mean, what's the philosophy of this Alpha-Obect? When eg the actual value of it is 0.5 and I know that it is increasing and now I alter the Increasing-Time to the double value of what it was before, my alpha value won't change to 0.25, as one might guess... so what's the philosophy???
    Thanks for your help...
    braveheart

    Thank you for your post Alex,
    though it's not quite the 'right answer' for that I searched but it gave me a good hint at where to search or what to try. So i have tested the alpha object with it's startTime and the actual time.
    As far as I've found it goes this way: assuming that you have an alpha object with decreasing and increasing capability and the in- and decreasingTime is 1000ms. Now the alpha value is computed as follows: the actualTime of your system (System.currentTimeInMillis) less the startedTime of your alphaObject, the result mod-divided through your in- or decreasingTime, this in turn gives you the rest of your in- or decreasing movement.
    Eg if in the above stated example the passedTime is 7300ms, then you are in the decreasing-mode and have still 700ms to go. Therefore the alphaValue will be 0.7. This at least is valid when you haven't set any in- or decreasingRampDuration... this makes the equation quite 'unpredictable'...
    But I find this philosophy quite nonsensical... because it don't take into account the actual movement but computes the alphaValue from the start, as if it had moved through the passedTime with the new in/decreasingTime... which really isn't the case... so I think that your velocity assumption isn't quite the case here??
    I must admit that the java3d functionality classes aren't really what you might expect from a java derived language. I don't think that I will ever again write a programm in java3d... it don't seem like real programming but having to fiddle with all kinds of inadequacies... well, again, thank you for your post...
    dominik

  • PhotoHolder - Bitmap/BitmapData Problems

    Hello guys, how are you?
    I'm trying to create an actionscript 3 class that receives an external image, adds it into a movieclip and adjusts it without corrupting the aspect ratio of the image.
    I've tried working with BitmapData and Bitmap only, but can not hit the calculations. Can anyone help me?
    Thank you,
    package
        import flash.display.Bitmap;
              import flash.display.BitmapData;
              import flash.display.DisplayObject;
              import flash.display.Loader;
              import flash.display.MovieClip;
              import flash.display.PixelSnapping;
              import flash.display.Sprite;
              import flash.events.Event;
              import flash.events.IOErrorEvent;
              import flash.geom.Matrix;
              import flash.geom.Rectangle;
              import flash.net.URLRequest;
              import flash.system.LoaderContext;
              public class PhotoHolder extends MovieClip
                        private var _loader:Loader;
                        public function PhotoHolder()
                        public function loadPhoto(urlImg:String):void
                                  _loader = new Loader();
                                  _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
                                  _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
                                  _loader.load(new URLRequest(urlImg));
                        private function onError(e:IOErrorEvent):void
                                  trace("ERROR!");
                        private function onComplete(e:Event):void
                                  var loadedImage:Bitmap = Bitmap(_loader.content);
                                  var bmd:BitmapData = new BitmapData(_loader.content.width, _loader.content.height, true);
                                  bmd.draw(loadedImage, null);
                                  this.holder.addChild(createBitmap(bmd));
                        private function createBitmap(bmd:BitmapData):Bitmap
                var bitmap:Bitmap = new Bitmap(bmd);
                bitmap.smoothing = true;
                setSize(bitmap, bmd.width, bmd.height, this.holder.x, this.holder.y);
                return bitmap;
            private function setSize(target:DisplayObject, contentWidth:Number, contentHeight:Number, targetWidth:Number, targetHeight:Number):void
                var w:Number = targetWidth;
                var h:Number = targetHeight;
                // maintain aspect ratio
                var containerRatio:Number = targetWidth / targetHeight;
                var imageRatio:Number = contentWidth / contentHeight;
                if (containerRatio < imageRatio) h = w / imageRatio;
                else                             w = h * imageRatio;
                target.width = w;
                target.height = h;
                //centre content - this might change based on your setup
                target.x = (targetWidth - w) * .5;
                target.y = (targetHeight -h) * .5;

    You´re right! It´s happening, the case is my movieclip. I will think about it. I made fell changes in the class, it´s more easy to read. Now, that is the principal methods:
    private function onComplete(e:Event):void
                                  var w:Number = this.width;
                                  var h:Number = this.height;
                                  var loadedImage:Bitmap = Bitmap(_loader.content);
                                  _ratio = _loader.content.height / _loader.content.width;
                                  this.addChild(resizeIt(loadedImage, w, h));
                        private function resizeIt(bitmap:Bitmap, maxW:Number, maxH:Number):Bitmap
                                 if (bitmap.width > maxW)
                                       bitmap.width = maxW;
                                       bitmap.height = bitmap.width * _ratio;
                              if (bitmap.height > maxH)
                                     bitmap.height = maxH;
                                    bitmap.width = bitmap.height / _ratio;
                              bitmap.smoothing = true;
                               return bitmap;
    But I have one more question:
    I'm reducing the size of the image to place it in the container. I'm not using scaleX and scaleY. How do I fill the container without losing image quality?

  • DisplayObject.alpha problem on MouseEvent

    Hello,
    I have a button (VehiclesButton) which on rollover I want it to trigger a mouse event so an image(VehiclesCentral) to the side of it (I've just set the alpha to 0 so its invisble, but its on the stage) will have its alpha increased to 100 and become visible
    VehiclesButton.addEventListener(MouseEvent.MOUSE_OVER,test);
    function  test(e:MouseEvent):void
    VehiclesCentral.DisplayObject.alpha = 100 ();
    When I publish this though I get no compiler errors, only an error when I actually go onto it and rollover the button. I get the following error message:
    TypeError: Error #1006: value is not a function.
    at QualityPortal_fla::MainTimeline/test()
    (Quality Protal_fla is the file name I am working on).
    Thanks
    Sean

    Try:
    VehiclesButton.addEventListener(MouseEvent.MOUSE_OVER,test);
    function  test(e:MouseEvent):void
         VehiclesCentral.alpha = 1;

  • Simple alpha problem...

    i'm not sure why my code is not working...
    onClipEvent (load) {
        this._alpha = 0;
    onClipEvent (enterFrame) {
        if (txt = 2) {
            _parent.pred2_mc._alpha = 0;
            _parent.pred_mc._alpha = 100;
            _parent.mut_mc._alpha = 0;
            _parent.par_mc._parent = 0;
            _parent.comp_mc._alpha = 0;
            _parent.comens_mc._alpha = 0;
    i have a hittest...and when that object is hit it will return a variable for txt...
    txt = 1 //for pred2_mc
    txt = 2 //for pred_mc
    etc...
    if the object is hit i would want this mc to have a 100 alpha then the others to set to 0...
    i've used this code before and its working fine..but i'm not sure why its not working this time...

    I haven't looked at the code as a whole, but...
    if (txt = 2) {
    should be
    if (txt == 2) {

  • Problem with scanning in PS CS6 - scanning process crashes

    Hi.
    Here is my hardware:
       Macbook pro 4 GB DDR3 core i5 with plenty of HD space
       Epson V700 scanner (6400 dpi scanning capability)
    My Software:
       Adobe CS6 trial
    What I want to do:
       Scan a typical photo that is 6 by 6 inches at 6400 dpi as a bitmap, for utmost quality
    What I tried:
       File -> Import -> Images from device -> then selected my scanner, set it to scan at 6400 dpi and save as a bitmap
    My problem:
        When the scanner head is done scanning and the progress bar for scanning the image completes and moves to the next step (presumably writing the image to the file), PS crashes and gives me an error log. It is far too detailed for me. I have no problem scanning images at lower resolutions like 1200 dpi. But this scanner is capable of 6400 dpi and I want to take full advantage of it. I cannot use the scanner software that came with teh scanner because tech support told me the scanner software has a 1.something GB file limit size. They told me 3rd party software like PS should be able to scan unlimited file sizes.
       I suspect the file size migh be too large (16 GB)
    My question:
       Is this a bug in the trial or something? Should PS be able to scan a 6 by 6 inch photo at 6400 dpi and save it as a bitmap?
    Any 1st thoughts? I imagine it would be useful to upload the error log. I can do that if it is ok to do so
    Thanks, your help is appreciated since I would lik eto scan this image at 6400 dpi. If I am given a solution, I will probably buy the full version

    I downloaded and placed the new Mac plugin that PDFerguson was talking about. I also made sure I had the latest drivers from EPson. I have the same problem. I tried a couple of different file formats, like TIFF (at 6400 dpi and billions of colors) and while "reading the TIFF file" it stops and tells me : "Could not complete your request because of a problem parsing the TIFF file.". Just to note, I scan to a new PS document, so it seems like it has scanned the image, but after a certain file size the driver/PS messes up the creation of the file. Then when PS reads that image data that it just made in some temporary location (which I am presuming is an improper image) into a new document (I say this because when PS opens a file it says "reading blah blah"), the parser (JPG, TIFF, etc....) crashes somewhere in the process of reading the file that it just wrote to temporary disk space into a new PS document.
    Because of these facts, I am led to believe that there seems to be some size limit after which PS or whatever is writing the temporarily scanned file where this file becomes corrupt. My suspicion of this as the cause of the problem is made darker from this experience: when I use the Apple OS scanning utility, and scan it at the dpi and color depth at which PS crashes, the apple utility does not crash, but instead produces a corrupt file on my disk. I say it is corrupt becasue the file is all black or white and has no scanned information. Likewise, when PS tries to open up those images, its parser for a particular file type fails, probably because it encounters an error.
    That sounds confusing so here is a diagram:
    Scanner invoked in PS => scans successfully at 6400 dpi and writes image data to scratch disk space (but this data is corrupt) =>PS tries to make a new document by reading this image data like it would open up a file from disk, using the appropriate format parser => because the iage data on scratch disk has been corrupted, the parser crashes as it encounters bad format data.
    When I ask PS to scan into BMP files, I get a vague error, which I presume is becasue the parser for BMP is quite primitive and will cast bad data as pixels anyways?
    From all this experimentation this is what I have concluded. The problem doesnt seem to be with how much RAM I have, or teh scanner driver itself, but the step where the software writes the scanned image data temporarily to disk (and messes up in doing so), causing any further image saving steps to fail, because the parser encounters an exception.
    Any thoughts from the engineers?

  • Problem with scanning in PS CS6

    Hi.
    Here is my hardware:
       Macbook pro 4 GB DDR3 core i5 with plenty of HD space
       Epson V700 scanner (6400 dpi scanning capability)
    My Software:
       Adobe CS6 trial
    What I want to do:
       Scan a typical photo that is 6 by 6 inches at 6400 dpi as a bitmap, for utmost quality
    What I tried:
       File -> Import -> Images from device -> then selected my scanner, set it to scan at 6400 dpi and save as a bitmap
    My problem:
        When the scanner head is done scanning and the progress bar for scanning the image completes and moves to the next step (presumably writing the image to the file), PS crashes and gives me an error log. It is far too detailed for me. I have no problem scanning images at lower resolutions like 1200 dpi. But this scanner is capable of 6400 dpi and I want to take full advantage of it. I cannot use the scanner software that came with teh scanner because tech support told me the scanner software has a 1.something GB file limit size. They told me 3rd party software like PS should be able to scan unlimited file sizes.
       I suspect the file size migh be too large (16 GB)
    My question:
       Is this a bug in the trial or something? Should PS be able to scan a 6 by 6 inch photo at 6400 dpi and save it as a bitmap?
    Any 1st thoughts? I imagine it would be useful to upload the error log. I can do that if it is ok to do so
    Thanks, your help is appreciated since I would lik eto scan this image at 6400 dpi. If I am given a solution, I will probably buy the full version

    Hi,
    I am sorry to hear that you are facing issues with PS. But you have posted this question on Acrobat Forum. People joined here have expertise in Acrobat only. Kindly post the same on http://forums.adobe.com/community/photoshop/general to get it addressed by PS experts.
    ~Sandeep V.

  • JPG to BMP conversion problems...

    Hi folks, I'm having a bit of trouble. I can't see why BufferedImage img is returning null. Can anyone spot anything?
        private void convertImages() {
            //Read all the files in a given directory in.  If they are images then convert them.
            File file;
            JFileChooser fc = new JFileChooser();
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = fc.showOpenDialog(fc);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();      // Get directory to file.
                File[] files = file.listFiles();  // Get file array
                outputField.setText("");
                outputField.append("Converting all images in " + file.getPath() +
                        "to bitmap images.\n  Images will be saved in "
                        + file.getParentFile().getPath() + File.separator + "rawdata.\n");
                File outputdirectory = null;
                if(new File(file.getParentFile().getPath()+File.separator+"rawdata").mkdir() || new File(file.getParentFile().getPath()+File.separator+"rawdata").exists()){
                    outputdirectory = new File(file.getParentFile().getPath()+File.separator+"rawdata");
                    outputField.append("Created directory: " + outputdirectory.getPath()+"\n");
                } else {
                    outputField.append("Unable to create a rawdata directory.");
                    return;
                for(File image_file : files){
                    if(isImage(image_file)){
                        outputField.append("Converting " + image_file.getName() + " to bitmap.\n");
                        try {
                            img = ImageIO.read(image_file);
                            output = new File(outputdirectory.getPath()+File.separator+image_file.getName()+".bmp");
                            ImageIO.write(img, "bmp", output);
                            img.flush();
                        } catch (IOException ex) {
                            outputField.append("Problem when trying to convert file: " + image_file.getName() + "\n");
                        } catch (IllegalArgumentException e){
                            e.printStackTrace();
                            outputField.append("Problem with image file. \n");
                    } else {
                        outputField.append("Ignored file " + image_file.getName() + " because it is not an image.\n");
                outputField.append("Job done.\n");
        }I'm getting this output:
    Converting all images in F:\Documents and Settings\Eric\My Documents\testnewto bitmap images.
      Images will be saved in F:\Documents and Settings\Eric\My Documents\rawdata.
    Created directory: F:\Documents and Settings\Eric\My Documents\rawdata
    Ignored file .DS_Store because it is not an image.
    Ignored file ._.DS_Store because it is not an image.
    Converting 1.jpg to bitmap.
    Problem with image file.
    Converting 2.jpg to bitmap.
    Problem with image file.
    Converting 3.jpg to bitmap.
    Problem with image file.
    Converting 4.jpg to bitmap.
    Problem with image file.
    Converting 5.jpg to bitmap.
    Problem with image file.
    Ignored file Results because it is not an image.
    Ignored file testnewtrain.txt because it is not an image.
    Ignored file Thumbs.db because it is not an image.
    Ignored file train.txt because it is not an image.
    Job done.And an error:
    java.lang.IllegalArgumentException: im == null!
            at javax.imageio.ImageIO.write(ImageIO.java:1457)
            at javax.imageio.ImageIO.write(ImageIO.java:1521)Obviously, for whatever reason img isn't initialising, but I can't see why not. It's probably something silly. Any suggestions?
    Eric
    Edited by: escocialite on Apr 9, 2008 2:42 PM

    Obviously, for whatever reason img isn't initialising, but I can't see why not.I ran your code through a test, and as expected, it performed flawlessly.
    It's probably something silly.Can't tell, since it worked for me.
    Any suggestions?Run this SSCCE which works flawlessly or me and see how it works for you.
    package graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.JFileChooser;
    public class LoadAndSaveImage {
       public void convertImages() {
          JFileChooser chooser = new JFileChooser();
          chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          chooser.showOpenDialog(null);
          File folder = chooser.getSelectedFile();
          File[] files = folder.listFiles();
          for (File file : files) {
             String name = file.getName();
             if (name.endsWith("jpg") || name.endsWith("JPG")) {
                BufferedImage img = null;
                File outFile = new File(folder.getPath() + File.separator + name + ".bmp");
                try {
                   img = ImageIO.read(file);
                   ImageIO.write(img, "bmp", outFile);
                   img.flush();
                } catch (IOException ex) {
                   ex.printStackTrace();
       public static void main(String[] args) {
          new LoadAndSaveImage().convertImages();
    }luck, db

Maybe you are looking for

  • On average, how many times do you have to restart ...

    Ever since I've been using the E71 (less than a month, a new set), I have to restart it about thrice daily. Mostly, the problem occurs while connecting the phone to the PC (Windows 7) when the USB connection type selector on the phone (which appears

  • Making a video input for iMac

    Anyone tried to modify the iMac to add a Videoinput? I'm electroni engineer and after disasembly my ibook, i think with a little patiente and some knowladge we can make a Video input. Any help?

  • Why I'm getting the jxls Error : Can't parse an expression rm.exec

    Hi, I used the RowSet in JXLS and it's working perfectly, but I'm getting Error when I use the SQL Reporting in JXLS Error : java.lang.RuntimeException: Can't parse an expression rm.exec('select name from Designer' ) My Java File : package net.sf.jxl

  • Question on runtime enviornment

    Pls tell me what is Runtime enviornment in Process Integration and also tell me what is the role of runtime enviornment in it.pls reply  soon

  • Force a commit statement

    Hello, Is it possible to automatically force a commit statement in a JSP page after you have inserted or updated a record ? Greetz