CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2005
    Posts
    78

    Smile Image format conversion

    Hi ,
    I am scanning an image and that image is in .dib format .
    Now i need to convert that image to jpeg,tif,gif.
    how can i convert dib to these formats ?
    Note:
    There is an option called save it as .bmp format .. so no issues when converting it to bitmap but i need to convert it other formats also.

    Idea
    is there any possiblity to use GDI+ to convert ?

    waiting for ur reply .
    Thanks,
    Venrag

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Image format conversion

    Yes, you can use GDI+ or other third party image libraries. Also, take a look at the articles at http://www.codeguru.com/Cpp/G-M/bitmap/. Some of them explain how to save to other formats.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    May 2005
    Posts
    4,954

    Re: Image format conversion

    You can do it with Image Class (GDI+).

    /EDIT: Marc was faster

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  4. #4
    Join Date
    Sep 2005
    Posts
    78

    Re: Image format conversion

    Any other methos other than GDI
    to convert a dib image to gif,jpg,tif


    thank u

    venrag

  5. #5
    Join Date
    May 2005
    Posts
    4,954

    Re: Image format conversion

    Quote Originally Posted by venrag
    Any other methos other than GDI
    to convert a dib image to gif,jpg,tif


    thank u

    venrag
    Why? What do you have against GDI ?

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  6. #6
    Join Date
    Sep 2005
    Posts
    78

    Smile Re: Image format conversion

    I don't have any thing against GDI+.

    I have a image which is scanned from the scanner and put in the View.
    This image is in the format of dib.

    I convert it in to bmp and save it in the disc.
    Suppose I want to save this dib image that is in the view in to
    gif,jpg or tif ,I have to first convert in to bmp and save it in the disc and
    then convert it to gif using GDI+ Image.

    what i want to do is to convert the dib Image from the view directly to
    gif,jpg ,tif.

    For this I have asked whether we have any other method.

    thank u
    venrag

  7. #7
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Image format conversion

    Have you checked the articles at http://www.codeguru.com/Cpp/G-M/bitmap/ like I said in my first reply?

    For example, take a look at http://www.codeguru.com/cpp/g-m/bitm...cle.php/c4915/ to save bitmaps to JPG files.

    NOTE: I would not recommend to save photos to GIF format because the GIF format only supports 256 colors and is not really suitable for photos.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  8. #8
    Join Date
    May 2005
    Posts
    4,954

    Re: Image format conversion

    Quote Originally Posted by venrag
    I don't have any thing against GDI+.

    I have a image which is scanned from the scanner and put in the View.
    This image is in the format of dib.

    I convert it in to bmp and save it in the disc.
    Suppose I want to save this dib image that is in the view in to
    gif,jpg or tif ,I have to first convert in to bmp and save it in the disc and
    then convert it to gif using GDI+ Image.

    what i want to do is to convert the dib Image from the view directly to
    gif,jpg ,tif.

    For this I have asked whether we have any other method.

    thank u
    venrag
    You don’t have to write to the disc you can create Image from stream ( Image::FromStream() ).

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  9. #9
    Join Date
    Sep 2005
    Posts
    78

    Smile Re: Image format conversion

    I have used the stream function.
    Iam passing the

    Code:
    	CWnd *pwnd=AfxGetMainWnd();
    	HWND hwnd =pwnd->GetSafeHwnd();
                    HDC hdc;
    	hdc=GetDC(hwnd);
    	Example_FromStream(hdc);
    Inside Example_FromStream(hdc)

    Graphics graphics(hdc);

    Image* pImage1 = NULL;
    Image* pImage2 = NULL;

    IStorage* pIStorage = NULL;
    IStream* pIStream1 = NULL;
    IStream* pIStream2 = NULL;
    HRESULT hr;
    Status stat;

    // Open an existing compound file, and get a pointer
    // to its IStorage interface.
    hr = StgOpenStorage(
    L"CompoundFile.cmp",
    NULL,
    STGM_READ|STGM_SHARE_EXCLUSIVE,
    NULL,
    0,
    &pIStorage);

    if(FAILED(hr))
    goto Exit;===>each time Iam getting failed
    because hr=-ve value.
    What is a CompoudFile.cmp
    So I only I went for the filename method.
    Canu helpme with Stream function

    By the way I want to reduce the memory capacity of the image
    so Iwant to convert it in to gif file
    No problem with the reduction of the color.

    thank u

  10. #10
    Join Date
    Sep 2005
    Posts
    78

    Thumbs up Re: Image format conversion

    Hi I got the conversion

    from bmp to jpg
    using GDI+ without saving the image to the disc.

    I have not used Stream method .
    Instead I got the idea from the below link
    http://www.codeguru.com/cpp/g-m/gdi/...cle.php/c3661/
    I have used CBitmap and Bitmap (GDI+) to get the handle of the
    Image in the view.

    "Thanks MarcG and GolanShahar"

    I have tested the BMP with MSPAINT I am getting the jpeg format
    memory size is correct.
    When I convert to giff I am getting little bit difference.
    Like in MSPAINT conversion 775kb -->35.5kb
    In GDI+ --->55.5kb

    I think this difference is because I have not reduced the color.

    I have to find out that.

    Thank u
    venrag

  11. #11
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Image format conversion

    [ Moved thread ]

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured