×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2011
    Location
    Final Fantasy Land
    Posts
    31

    Lightbulb Example usage for How to read images to Symbian bitmap

    My old topic: How to display image (image's path is inputted by user)

    I have solved my problem with wizard_hu's help. And I saw this article doesn't have example usage. I searched in google. I found that there are someones got someproblems with this article and didn't solve them. So I want to show them a way to use this article.
    How to read images to Symbian bitmap

    ImageConverter.h
    Code:
    #ifndef __IMAGECONVERT_h__
    #define __IMAGECONVERT_h__
    
    
    #include <e32base.h>
    #include <coecntrl.h>
    #include <w32std.h>
    #include <e32std.h> 
    #include <ImageConversion.h>
    
    class CFbsBitmap;
    class CBitmapScaler;
    
    class MImageConverterObserver
    {
    	public:
    		virtual void ConversionComplete(TInt aError) = 0;
    };
     
    class CImageConverter : public CActive
    {
    	public:
    	    CImageConverter(MImageConverterObserver* aObserver);
    	    void ConstructL(const TDesC& aFileName);
    	    ~CImageConverter();
    	public:
    	    CFbsBitmap* Bitmap();
    	protected:
    		void DoCancel();
    		void RunL();
    	private:
    		MImageConverterObserver*	iObserver;
    		CImageDecoder*			iImageDecoder;
    		CFbsBitmap*				iImage;
    		TFileName				iImageName;
    };
    
    #endif // __IMAGECONVERT_h__
    ImageConverter.cpp
    Code:
    #include <eikenv.h>
    #include <BitmapTransforms.h>
    #include "imageconverter.h"
     
    CImageConverter::CImageConverter(MImageConverterObserver* aObserver)
    :CActive(0)
        {
        iObserver = aObserver;
    	CActiveScheduler::Add(this);
        }
     
    CImageConverter::~CImageConverter()
    {
    	Cancel();
    	//delete iImage;
    	delete iImageDecoder;
    }
     
     
    void CImageConverter::ConstructL(const TDesC& aFileName)
    {
    	iImageName.Copy(aFileName);
    	
    	if(iImageName.Length())
    	{		
    		if(iImageDecoder)
    		{
    			delete iImageDecoder;
    			iImageDecoder = 0;
    		}
    		iImageDecoder = CImageDecoder::FileNewL(CCoeEnv::Static()->FsSession(),aFileName);
     
    		delete iImage;
    		iImage = NULL;
    		iImage = new(ELeave)CFbsBitmap();
    		iImage->Create(iImageDecoder->FrameInfo(0).iOverallSizeInPixels,iImageDecoder->FrameInfo(0).iFrameDisplayMode);
     
    		iImageDecoder->Convert(&iStatus,*iImage,0);
    		SetActive();
    	}
    }
    
     
    void CImageConverter::DoCancel()
    {
    	iImageDecoder->Cancel();
    }
     
    //Transfering ownership of image, so calling function must delete it.
    CFbsBitmap* CImageConverter::Bitmap()
    {
    	return iImage;
    }
     
    	
    void CImageConverter::RunL()
    {
    	if(iStatus == KErrNone)
    	{
    		iObserver->ConversionComplete(iStatus.Int());
    	}
    	else
    	{
    		delete iImage;
    		iImage = 0;
    	}
    }
    Example usage:
    Code:
    //Edit View.h or Container.h:
    #include "ImageConverter.h"
    // CLASS DECLARATION
    class CImageReaderAppView : public CCoeControl, MImageConverterObserver
    
    //Add more function to class:
    public: //MImageConverterObserver
    	void ConversionComplete(TInt aError);
    
    //Add more data to class:
    private://data
    	CFbsBitmap* iBitmap;
    	CImageConverter* iImageConverter;
    
    //Edit ContructL in View.cpp or Container.cpp:
    void CImageReaderAppView::ConstructL(const TRect& aRect)
    	{
    	// Create a window for this application view
    	CreateWindowL();
    
    	// Set the windows size
    	SetRect(aRect);
    
    	//Convert Image to Bitmap
    	iImageConverter = new (ELeave) CImageConverter(this);
    	
    	iImageConverter->ConstructL(_L("\\Data\\Images\\lokki2.jpg"));
    	// Activate the window, which makes it ready to be drawn
    	ActivateL();
    	}
    
    //Draw picture:
    if(iBitmap)
    	{
    	gc.BitBlt(TPoint(0,0), iBitmap);
    	}
    Note: You must add fbscli.lib and imageconversion.lib to your MMP file.

  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,143

    Re: Example usage for How to read images to Symbian bitmap

    in a class you would want to use the code, you would just derive MImageConverterObserver and implement the function defined in the MImageConverterObserver. Then just have the CImageConverter as a member variable of that same class, and construct instance of it, just as you have done.

    Anyway do use a drive letter with the path. as well as use the Bitmap() from the CImageConverter , instead of iBitmap of the class when drawing.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Location
    Final Fantasy Land
    Posts
    31

    Re: Example usage for How to read images to Symbian bitmap

    Quote Originally Posted by symbianyucca View Post
    Anyway do use a drive letter with the path. as well as use the Bitmap() from the CImageConverter , instead of iBitmap of the class when drawing.
    I got your idea. It will make the program faster. thanks

Similar Threads

  1. Replies: 5
    Last Post: 2009-03-09, 08:24
  2. How to read images from the RSS Feed URLs in JavaME
    By sreekanth288 in forum Mobile Java General
    Replies: 1
    Last Post: 2009-01-27, 11:48
  3. Example: How to embed images in Rich Text Editor
    By omerkarim in forum Symbian User Interface
    Replies: 1
    Last Post: 2007-11-16, 14:37
  4. How to get GPRS status in Series60 V1.2(Symbian V6.1, 7650 for example)
    By daveice in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2006-01-09, 09:13

Posting Permissions

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