Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7540153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:34:12+00:00 2026-05-30T07:34:12+00:00

I have a flex application in which I have to convert a jpeg picture

  • 0

I have a flex application in which I have to convert a jpeg picture taken by camera using base64 converter and then upload the result to sqlite database (as MEDIUMBLOB). The code looks like this:

MXML declarations of images:

        <s:Group width="480" height="304">
            <s:Label x="0" y="0" width="100%" height="34" backgroundColor="#4D4D4D"
                     color="#FFFFFF" fontSize="30" text="   Select photo" verticalAlign="middle"/>
            <s:Image id="image" x="10" y="42" width="217" height="246" />
            <s:Image id="image2" x="10" y="42" width="217" height="246" source = "@Embed(source='skins/PhotoNotAvailable.jpg')"/>
            <s:Button x="235" y="42" width="235" height="84" label="Take a Picture"
                      click="captureImage(event)" enabled="{CameraUI.isSupported}" fontSize="30"/>
            <s:Button x="235" y="150" width="235" height="70" label="Delete"
                      click="deletePhoto(event)" fontSize="30"/>
        </s:Group>

Scripts for taking a picture and convertion:

//Taking the pictures

        protected function application1_applicationCompleteHandler(event:FlexEvent):void {
            image.setVisible(true);
            image2.setVisible(false);
            if (CameraUI.isSupported){
                var mediaPromise:MediaPromise;
                camera = new CameraUI();
                camera.addEventListener(MediaEvent.COMPLETE, onComplete);
                camera.addEventListener(ErrorEvent.ERROR, onError);
            } else {
            }
        }

        protected function view1_activateHandler(event:Event):void
        {
            conn  = data as SQLConnection;
        }

        private function captureImage(event:MouseEvent):void {
            camera.launch(MediaType.IMAGE);
        }
        private function onError(event:ErrorEvent):void {
            trace("error has occurred");
        }
        private function onComplete(event:MediaEvent):void {
            var mediaPromise:MediaPromise = event.data;
            image.source = mediaPromise.file.url;
            pictureTaken = true;
        }

//Convertion and uploading to database

protected function AddHandler(event:MouseEvent):void

//irrelevant code skipped

                insertStmt = new SQLStatement();
                insertStmt.sqlConnection = conn;
                var insertSQL:String = ("INSERT INTO RecipeDB (RecipeID, Name, Category, Origin, Recipe, Favorite, Image)" + "VALUES (:RecipeID, :Name, :Category, :Origin, :Recipe, :Favorite, :Image)");
                insertStmt.text = insertSQL;
                    if(pictureTaken)
                {
                    var jencoder:JPEGEncoder = new JPEGEncoder(75);  
                    var imageByteArray:ByteArray = jencoder.encode(image.bitmapData);
                    var baseEncoder:Base64Encoder = new Base64Encoder();
                    baseEncoder.encodeBytes(imageByteArray); 
                    encodedBytes = baseEncoder.toString();
                }
                else
                {
                    var jencoder:JPEGEncoder = new JPEGEncoder(75);  
                    var imageByteArray:ByteArray = jencoder.encode(image2.bitmapData);
                    var baseEncoder:Base64Encoder = new Base64Encoder();
                    baseEncoder.encodeBytes(imageByteArray); 
                    encodedBytes = baseEncoder.toString();

                }
                insertStmt.parameters[":RecipeID"] = ID as int;
                insertStmt.parameters[":Name"] = NameArea.text;
                insertStmt.parameters[":Category"] = TypeArea.text;
                insertStmt.parameters[":Origin"] = OriginArea.text;
                insertStmt.parameters[":Recipe"] = RecipeArea.text;
                insertStmt.parameters[":Favorite"] = 0 as int;
                insertStmt.parameters[":Image"] = encodedBytes;
                insertStmt.execute();
}

//Deleting photo
            protected function deletePhoto(event:MouseEvent):void
        {
            pictureTaken = false;
            image.setVisible(false);
            image2.setVisible(true);
        }

Now, if no picture was taken, the program uploads skins/PhotoNotAvailable.jpg to the DB correctly, but if the picture was taken or taken and deleted, the program hangs (android asks if to close it or wait). I have checked the size of taken pictures and it does not exceed MEDIUMBLOB`s size (picture has ca. 2 MBytes). What could be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:34:14+00:00Added an answer on May 30, 2026 at 7:34 am

    My first thought from your description of what happens is “a breakpoint.” The only time my phone gives me that message is when I’m debugging and it’s stopped on a break point for too long.

    You might cast your event.data as MediaPromise

        private function onComplete(event:MediaEvent):void {
            var mediaPromise:MediaPromise = event.data as MediaPromise;
            image.source = mediaPromise.file.url;
            pictureTaken = true;
        }
    

    Though that may just be a copying error.

    So far as I can tell you don’t need to base64 encode the image data. It’s already encoded and ready to be inserted into a database. Perhaps “double-encoding” is somehow creating a problem. ???

    I would change

    if(pictureTaken)
    {
        var jencoder:JPEGEncoder = new JPEGEncoder(75);  
        var imageByteArray:ByteArray = jencoder.encode(image.bitmapData);
        var baseEncoder:Base64Encoder = new Base64Encoder();
        baseEncoder.encodeBytes(imageByteArray); 
        encodedBytes = baseEncoder.toString();
    }
    else
    {
        var jencoder:JPEGEncoder = new JPEGEncoder(75);  
        var imageByteArray:ByteArray = jencoder.encode(image2.bitmapData);
        var baseEncoder:Base64Encoder = new Base64Encoder();
        baseEncoder.encodeBytes(imageByteArray); 
        encodedBytes = baseEncoder.toString();
    }
    
    insertStmt.parameters[":RecipeID"] = ID as int;
    insertStmt.parameters[":Name"] = NameArea.text;
    insertStmt.parameters[":Category"] = TypeArea.text;
    insertStmt.parameters[":Origin"] = OriginArea.text;
    insertStmt.parameters[":Recipe"] = RecipeArea.text;
    insertStmt.parameters[":Favorite"] = 0 as int;
    insertStmt.parameters[":Image"] = encodedBytes;
    insertStmt.execute();
    

    to

    var jencoder:JPEGEncoder = new JPEGEncoder(75);
    var imageByteArray:ByteArray;
    if(pictureTaken)
    {
        imageByteArray = jencoder.encode(image.bitmapData);
    }
    else
    {
        imageByteArray = jencoder.encode(image2.bitmapData);
    }
    
    insertStmt.parameters[":RecipeID"] = ID as int;
    insertStmt.parameters[":Name"] = NameArea.text;
    insertStmt.parameters[":Category"] = TypeArea.text;
    insertStmt.parameters[":Origin"] = OriginArea.text;
    insertStmt.parameters[":Recipe"] = RecipeArea.text;
    insertStmt.parameters[":Favorite"] = 0 as int;
    insertStmt.parameters[":Image"] = imageByteArray;
    insertStmt.execute();
    

    If for some reason you still want the base64 encoding and it’s not creating the problem, I would still suggest refactoring the code like this to save duplication since the only thing that varies between the two if branches is the source of the bitmap data.

    var jencoder:JPEGEncoder = new JPEGEncoder(75);  
    var imageByteArray:ByteArray;
    if(pictureTaken)
    {
        imageByteArray = jencoder.encode(image.bitmapData);
    }
    else
    {
        imageByteArray = jencoder.encode(image2.bitmapData);
    }
    var baseEncoder:Base64Encoder = new Base64Encoder();
    baseEncoder.encodeBytes(imageByteArray); 
    encodedBytes = baseEncoder.toString();
    

    However, this is just a first stab at it. It would be useful to see the code all together. I’m assuming that encodedBytes is a String available to the whole class? I can’t see how/when AddHandler is invoked, so I also can’t tell variable states when it is called (which could be related to the problem). It would also be useful to know what’s happening after the AddHandler is completed. Perhaps it’s an error occurring after the insert statement that is hanging up?

    Did you debug it and get any errors to share?

    I know the post is a month old, so maybe you already figured it out. Maybe you could share it so others don’t make the same mistake. Either way, I hope this can help someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have flex application consisting of several modules which is configured using maven. I'm
We have a Flex application which has several 'pages' worth of content. Each time
I have a flex application which is configured with blazeds sever and i am
I have a Canvas in a Flex application which has items inside it that
I have a Flex application that calls a function which searches a large document
I have a Flex application where I'm using a Canvas to contain several other
I have a flex application in which I have a TabNavigator with multiple tabs
I have a Flex 4.5.1 application which loads another swf file (as a module
I have a Flex application which references a separate MXML file as a template
I have a flex application which use DragManager. When I'm loading this application into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.