×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: Loading Image

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Loading Image

    Hi All!

    I am trying to load and display an image that has been taken by the camera. Following is my code, I am trying to create the image without CActive as it is easier. (Hate ASync makes for a more complicated application) Anyway my application just seems to hang, was hoping if anyone out there had any similar problems or if they could see something wrong with my code.

    Oh the Camera image is taken via call
    iCamera->PrepareImageCaptureL(CCamera::EFormatExif, SIZE_INDEX);

    so the format is EFormatExif which is jpeg with exif meta data right? So I think the mimetype below is correct.

    Code:
    void CCameraController::ImageReady(CFbsBitmap* /*aBitmap*/, HBufC8* aData, TInt aError)
    	{
    		if(aError == KErrNone && aData)
    		{
    		
    		RFs fSession = CCoeEnv::Static()->FsSession();
    		User::LeaveIfError(fSession.Connect());
    		
    		CImageDecoder* decoder = CImageDecoder::DataNewL(fSession, aData->Des(), _L8("image/jpg"), CImageDecoder::EOptionAlwaysThread);
    		CleanupStack::PushL(decoder);
    		
    		TFrameInfo iFrameInfo = decoder->FrameInfo(0);
    		CFbsBitmap* bitmap = new (ELeave)CFbsBitmap();
    		iBitmap = bitmap;
    		bitmap->Create(iFrameInfo.iOverallSizeInPixels, iFrameInfo.iFrameDisplayMode);
    			
    		TRequestStatus request = KRequestPending;
    		decoder->Convert(&request, *bitmap);		
    		User::WaitForRequest(request);
    		
    		CleanupStack::PopAndDestroy(decoder);
    		fSession.Close();
    		
    		bitmap_is_ready = ETrue;
    		parent->DrawNow();
    		}
    	}
    Regards,

    Jonah Khan
    Last edited by jonahkhan1; 2008-07-21 at 13:52.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: Loading Image

    If you see TRequestStatus passed to some method of a C-class, User::WaitForRequest usually will not work, you have to create an active object.

    Background: while R-classes are (usually) forwarding your request directly to an other process (File Server, Socket Server, etc.), C-classes usually use an active object for that. And User::WaitForRequest blocks everything in your thread, including this AO.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: Loading Image

    Also I am do not mind if the thread is blocked while the conversion is taking place. As long as the conversion does take place. Which currently doesnt happen as the whole application hangs foreever. Infact I can't even close it down.
    Last edited by jonahkhan1; 2008-07-21 at 12:54.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: Loading Image

    In the previous post I have forgotten to point at the Wiki, however it is never too lata: if you search for CImageDecoder, you will find some clues.

    Anyway, here are the reflections:
    Quote Originally Posted by jonahkhan1 View Post
    I did try using CActive however the Convert call requests for a TRequestStatus not iStatus from the Cactive object where iStatus = TStatus.
    There are no such miracles, compiler can not see any difference between &iStatus and &request, given that both of them are TRequestStatus-es.
    So the program doesnot seem to compile.
    In such cases remember to read and post the exact error message. The message is always true.
    Also I am do not mind if the thread is blocked while the conversion is taking place. As long as the conversion does take place. Which currently doesnt happen as the whole application hangs foreever. Inface I can't even close it down.
    "You do not mind" is a nice thing, however the image conversion would also run in your thread, and it obviously can not run, if the thread is blocked.
    Closing the application also requires interaction, it is normal that a blocked application can not be closed, though it is going to die with ViewSvr 11 panic sooner or later (if you do not see panic codes, check http://wiki.forum.nokia.com/index.ph...ded_panic_code).

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: Loading Image

    Using the option EOptionAlwaysThread only means that the time-consuming bits of the processing occur in another thread. Unfortunately it will still use active objects internally to wrap the client-server interaction between threads in this case, so you can't block your main thread.

    Once you understand them, active objects are actually much easier to work with than threads.

    In your case it sounds like you need to fix a simple compilation error. Have you looked for CImageDecoder examples in the wiki? I think generally iStatus is of type TRequestStatus and you need to pass the address of your iStatus member to convert (i.e. &iStatus).

    Sorcery

  6. #6
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: Loading Image

    Sorry my mistake regarding the TRequestStatus, I had an object called iStatus that was hiding the CActive iStatus.

    I have now subclassed CActive, and also looked at the Wiki link, I have the now have the following code. The application now crashes and know error codes are displayed.

    I think it maybe todo with this line

    iDecoder = CImageDecoder:ataNewL(fSession, aData->Des(), _L8("image/jpg"), CImageDecoder::EOptionNone);

    as I said before the format I am taking the image in is CCamera::EFormatExif. should I use imahe/jpg as the mimetype?


    Code:
    void CCameraController::ImageReady(CFbsBitmap* /*aBitmap*/, HBufC8* aData, TInt aError)
    	{
    		if(aError == KErrNone && aData && !IsActive())
    		{
    		StopDisplayCamera();
    		
    		RFs fSession = CCoeEnv::Static()->FsSession();
    		User::LeaveIfError(fSession.Connect());
    		
    		iDecoder = CImageDecoder::DataNewL(fSession, aData->Des(), _L8("image/jpg"), CImageDecoder::EOptionAlwaysThread);
    		
    		TFrameInfo iFrameInfo = iDecoder->FrameInfo(0);
    		CFbsBitmap* bitmap = new (ELeave)CFbsBitmap();
    		bitmap->Create(iFrameInfo.iOverallSizeInPixels, iFrameInfo.iFrameDisplayMode);
    	
    			iDecoder->Convert(&iStatus, *bitmap);		
    			SetActive();
    		}
    	}
    Last edited by jonahkhan1; 2008-07-21 at 13:49.

  7. #7
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Loading Image

    The application now crashes and know error codes are displayed.
    what is the error displayed ???

    also when ever posting any code, wrap it around [code ] and [/code ] tags... (without spaces).... it will be a lot easier to read them with Indentation ..
    Amit Kankani
    Nokia Developer Champion

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: Loading Image

    There are no error codes displayed, I am kicked straight out. I haven't anything to go by.

    I have updated my previous relply below with the [code ] tags now.

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: Loading Image

    Quote Originally Posted by jonahkhan1 View Post
    I have now subclassed CActive, and also looked at the Wiki link, I have the now have the following code. The application now crashes and know error codes are displayed.
    Remember that this is a developer discussion board, and not a chat. So if you want some help, you might consider being specific. We love such messages 'now crashes and now error codes are displayed'. Guess what is missing.

    I think it maybe todo with this line

    iDecoder = CImageDecoder:ataNewL(fSession, aData->Des(), _L8("image/jpg"), CImageDecoder::EOptionNone);

    as I said before the format I am taking the image in is CCamera::EFormatExif. should I use imahe/jpg as the mimetype?
    CImageDecoder usually succeeds in recognizing filetypes in its own, so that should not be the first thing to check.

    If you enable Just In Time debugging in the emulator preferences, and execute your code in debug mode, Carbide is going to show you what is happening in the moment of the panic.
    RFs fSession = CCoeEnv::Static()->FsSession();
    User::LeaveIfError(fSession.Connect());
    This is not a great idea, since CONE already has its file server session connected. In fact the upper line copies the session returned by CCoeEnv::FsSession, a reference would be better:
    Code:
    RFs &fSession = CCoeEnv::Static()->FsSession();
    this way you eliminate the problem possibly raised by the fact you are passing a local variable to CImageDecoder, which is going to be invalidated sooner or later.
    CFbsBitmap* bitmap = new (ELeave)CFbsBitmap();
    Note that if you do not store the pointer to your bitmap in a member variable, it is going to be hard to use. The initial post contained some iBitmap, that was a good idea.

  10. #10
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: Loading Image

    Sorry, just to be clear I will enter my current code and also explain and ask a few questions.

    Firstly am I correct in assuming the emulator doesnt support the Camera? When I try the emulator it returns "Feature Not supported (-5)".

    I am testing directly on the device, without on device debugging as I only have the express edition of carbide.

    The updated code I am now using is listed below, it has been updated with the recommendations, again the only thing that happens is the application crashes and NO messages/panic codes are displayed

    Code:
    void CCameraController::ImageReady(CFbsBitmap* /*aBitmap*/, HBufC8* aData, TInt aError)
    	{
    		if(aError == KErrNone && aData && !IsActive())
    		{
    		StopDisplayCamera();
    		
    		delete iBitmap;
    		iBitmap = NULL;
    		delete iDecoder;
    		iDecoder = NULL;
    		
    		RFs &fSession = CCoeEnv::Static()->FsSession();
    		
    		iDecoder = CImageDecoder::DataNewL(fSession, aData->Des(), _L8("image/jpg"), CImageDecoder::EOptionNone);
    		
    		TFrameInfo iFrameInfo = iDecoder->FrameInfo(0);
    		iBitmap = new (ELeave)CFbsBitmap();
    		iBitmap->Create(iFrameInfo.iOverallSizeInPixels, iFrameInfo.iFrameDisplayMode);
    		
    		iDecoder->Convert(&iStatus, *iBitmap);		
    		SetActive();
    		
    		}
    	}
    Regards,

    Jonah Khan

  11. #11
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Loading Image

    Firstly am I correct in assuming the emulator doesnt support the Camera? When I try the emulator it returns "Feature Not supported (-5)".
    i think yes, you are correct...


    again the only thing that happens is the application crashes and NO messages/panic codes are displayed
    are you sure on this... have you for sure enabled panic code... ?
    do a thing, in constructl of Appui, add these lines of code in the begining:
    Code:
    HBufC* tempBuf = NULL;
    tempBuf->Des().Zero();
    this should give you Kern-Exec 3. If you are not able to see this Kern-Exec 3, then you have probably missed something in enabling the panic codes...
    how to enable extended panic codes ? see wiki and search "extended panic code"

    hope this helps !
    Amit Kankani
    Nokia Developer Champion

  12. #12
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: Loading Image

    Quote Originally Posted by jonahkhan1 View Post
    Firstly am I correct in assuming the emulator doesnt support the Camera? When I try the emulator it returns "Feature Not supported (-5)".
    It is actually mentioned in the release notes: emulator does not support the camera.
    However someone said a few days ago that if you download the E-series plugin, it adds some camera emulation, I have not checked.

    Your code seems to be OK, given that you get KErrNone and aData is not NULL.
    You can try adding a simple "User::LeaveIfError(aError);", and some panic if aData is NULL, if you want to test.

    Otherwise check your RunL, that is the place where you should pass iBitmap to the control and invoke DrawNow.

  13. #13
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: Loading Image

    I have added the extended panic codes to the application,

    now I get a nice fat Kern-Exec 3 displayed when the application crahses. Which is does at this point

    iDecoder->Convert(&iStatus, *iBitmap);

    I have checked iBitmap in fact I delete it and set it to null before use.

    The AppView pulls iBitmap from the Controller class if I have set a boolean in and draws it in the Draw method

    Code:
    void CUVCameraAppView::Draw(const TRect& /*aRect*/) const
    {
    
    .......
    
    if(iCameraController->Status() == EImage && iCameraController->IsBitmapReady())
    {
        CFbsBitmap* bitmap = iCameraController->Bitmap();		
        gc.BitBlt(drawRect.iTl, bitmap);
    }
    
    .......
    
    }

  14. #14
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: Loading Image

    Perhaps I should display my complete class, maybe I am doing something VERY wrong further out

    Here is the controller class

    Code:
    #include "CameraController.h"
    #include <coemain.h>
    #include <e32debug.h>
    #include <aknglobalnote.h>
    
    class CUVCameraAppView;
    
    CCameraController::CCameraController() : CActive(CActive::EPriorityStandard), iCameraStatus(EConstructed), bitmap_is_ready(EFalse), SIZE_INDEX(0)
    	{
    	CActiveScheduler::Add(this);
    	}
    
    CCameraController::~CCameraController()
    	{
    	Close();
    	Cancel();
    	
    	delete iCamera;
    	iCamera = NULL;
    	
    	delete iDecoder;
    	iDecoder = NULL;
    	}
    
    CCameraController* CCameraController::NewLC()
    	{
    	CCameraController* self = new (ELeave)CCameraController();
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    	}
    
    CCameraController* CCameraController::NewL()
    	{
    	CCameraController* self=CCameraController::NewLC();
    	CleanupStack::Pop(); // self;
    	return self;
    	}
    
    void CCameraController::ConstructL()
    	{
    	iCamera = CCamera::NewL(*this, 0);
    	iCamera->CameraInfo(iInfo);
    	
    	TInt formats = iInfo.iNumImageSizesSupported;
    	TSize size;
    	SIZE_INDEX = 0;
    		
    	for(TInt i=0;i<formats;i++)
    	{	
    		iCamera->EnumerateCaptureSizes(size, i, CCamera::EFormatExif);
    		
    		if(size.iWidth == 640 && size.iHeight == 480)
    		{
    		SIZE_INDEX = i;
    		break;
    		}
    	}
    	}
    
    ///////////////////////////////////////////////////////////////////////
    
    //CONTROLLER FUNCTIONS
    
    TCameraStatus CCameraController::Status()
    	{
    	return iCameraStatus;
    	}
    
    void CCameraController::InitCamera()
    	{
    	if(iCameraStatus == EConstructed)
    		iCamera->Reserve();
    	else if(iCameraStatus == EReserveComplete)
    		iCamera->PowerOn();
    	}
    
    void CCameraController::DisplayCamera(CCoeControl* surface)
    	{
    	
    	parent = surface;
    	
    	bitmap_is_ready = EFalse;
    	
    	if(iCameraStatus == EReady)
    		{
    		TSize size = TSize(320, 240);
    		iCamera->StartViewFinderBitmapsL(size);
    		iCameraStatus = ECamera;
    		}
    	}
    
    void CCameraController::TakePicture()
    	{
    	if(iCameraStatus == ECamera)
    		{
    		iCamera->PrepareImageCaptureL(CCamera::EFormatExif, SIZE_INDEX);
    		iCamera->CaptureImage();
    		}
    	}
    
    void CCameraController::StopDisplayCamera()
    	{
    		if(iCameraStatus == ECamera)
    			{
    			iCamera->StopViewFinder();
    			iCameraStatus = EReady;
    			bitmap_is_ready = EFalse;
    			}
    	}
    TBool CCameraController::IsBitmapReady()
    	{
    	return bitmap_is_ready;
    	}
    
    CFbsBitmap* CCameraController::Bitmap()
    	{
    	return iBitmap;
    	}
    
    void CCameraController::SetBitmapNotReady()
    	{
    	bitmap_is_ready = EFalse;
    	}
    
    void CCameraController::Close()
    	{
    	StopDisplayCamera();
    	iCamera->PowerOff();
    	iCameraStatus = EClosed;
    	}
    
    ///////////////////////////////////////////////////////////////////////
    
    // MCameraObserver
    
    void CCameraController::ReserveComplete(TInt /*aError*/)
    	{
    	iCameraStatus = EReserveComplete;
    	iCamera->PowerOn();
    	}
    
    void CCameraController::PowerOnComplete(TInt /*aError*/)
    	{
    	iCameraStatus = EReady;
    	}
    
    void CCameraController::ViewFinderFrameReady(CFbsBitmap& aFrame)
    	{
    	if(iCameraStatus == ECamera)
    		{
    		iBitmap = &aFrame;
    		bitmap_is_ready = ETrue;
    		parent->DrawNow();
    		}
    	}
    
    void CCameraController::ImageReady(CFbsBitmap* /*aBitmap*/, HBufC8* aData, TInt aError)
    	{
    		if(aError == KErrNone && aData && !IsActive())
    		{
    		StopDisplayCamera();
    		
    		delete iBitmap;
    		iBitmap = NULL;
    		delete iDecoder;
    		iDecoder = NULL;
    		
    		RFs &fSession = CCoeEnv::Static()->FsSession();
    		
    		iDecoder = CImageDecoder::DataNewL(fSession, aData->Des(), _L8("image/jpg"), CImageDecoder::EOptionNone);
    		
    		TFrameInfo iFrameInfo = iDecoder->FrameInfo(0);
    		iBitmap = new (ELeave)CFbsBitmap();
    		iBitmap->Create(iFrameInfo.iOverallSizeInPixels, iFrameInfo.iFrameDisplayMode);
    		
    		iStatus = KRequestPending;
    		iDecoder->Convert(&iStatus, *iBitmap);
    		SetActive();
    		
    		}
    	}
    
    void CCameraController::FrameBufferReady(MFrameBuffer* /*aFrameBuffer*/, TInt /*aError*/)
    	{
    	
    	}
    
    ///////////////////////////////////////////////////////////////////////
    
    
    //CActive
    
    void CCameraController::RunL()
    	{
    	delete iDecoder;
    	iDecoder = NULL;
    	
    	bitmap_is_ready = ETrue;
    	iCameraStatus = EImage;
    	parent->DrawNow();
    	}
    
    void CCameraController::DoCancel()
    	{
    	if(iDecoder)
    		iDecoder->Cancel();
    	}
    	
    TInt CCameraController::RunError(TInt aError)
    	{
    	CAknGlobalNote* iGlobalNote = CAknGlobalNote::NewL();
    	CleanupStack::PushL( iGlobalNote );
    	iGlobalNote->ShowNoteL(EAknGlobalConfirmationNote, _L("RUN ERROR"));
    	CleanupStack::PopAndDestroy();
    	}

  15. #15
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Loading Image

    iDecoder->Convert(&iStatus, *iBitmap);

    I have checked iBitmap in fact I delete it and set it to null before use.
    thats the exact reason

    well you have to delete the old bitmap, recreate a new one, and set its size too. If you ever pass *NULL, it will try to dereference a NULL and would result in BIG FAT Kern-Exec 3

    so do a new CFBsBitmap(); and then also setSize for that bitmap before passing it to decode function
    Amit Kankani
    Nokia Developer Champion

Similar Threads

  1. Opening a JPEG Image
    By ummarbhutta in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-02-15, 06:34
  2. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  3. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31
  4. Loading Image data from 'raw' bytes
    By LongSteve in forum Mobile Java General
    Replies: 2
    Last Post: 2002-11-20, 17:38

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×