Board index » cppbuilder » Strange different behaviour between .BMP and jpeg-converted .BMP

Strange different behaviour between .BMP and jpeg-converted .BMP

Trying to use a function which is able to convert a TBitmap to another
TBitmap, I got a different behaviour between the following to cases:

1) using a .bmp-file directly created from a standard graphics program
2) using a .jpg-file also directly created from a standard graphics
program. This one I tried to convert inside BCB to a .bmp file and use
it with the same function (see code-snippet below)

Result:
  tst0.bmp look quite similar in both cases 1) und 2)
  tst1.bmp look quite different. The resulting picture's  right margin
seems to have been cutted and it seems to have been stretched,

 if(ExtractFileExt(article_filename)==".bmp") {
    src_bitmap->LoadFromFile(article_filename);
  }
  else if(ExtractFileExt(article_filename)==".jpg")  {
    TJPEGImage *src_jpg_image=new TJPEGImage;
    src_jpg_image->LoadFromFile(article_filename);
    src_bitmap->Width=src_jpg_image->Width;
    src_bitmap->Height=src_jpg_image->Height;
    src_bitmap->Canvas->Draw(0, 0, src_jpg_image);
    TPicture *picture=new TPicture;
    picture->Assign(src_bitmap);

    TMemoryStream *mem_stream=new TMemoryStream();
    picture->Bitmap->SaveToStream(mem_stream);
    mem_stream->Position=0;
    src_bitmap->LoadFromStream(mem_stream);
    delete mem_stream;
  }
  else
    return;

  Graphics::TBitmap *dst_bitmap=new Graphics::TBitmap;

  MY_FUNC(dst_bitmap, src_bitmap);

  src_bitmap->SaveToFile("c:\\tst0.bmp");
  dst_bitmap->SaveToFile("c:\\tst1.bmp");

So my question: Is in the conversion in the .jpg-case an obvious
error, so the resulting .bmp-file is a problematic one?

Perhaps there is even a much more easier way to convert a jpeg-file's
bitmap in a .bmp-bitmap. I tried it another way, but MY_FUNC()
contains ScanLine(), which seems to last a half eternity to be
executed for each line of a comperssed picture (, so I decided to
convert it into a uncompressed bitmap for fast processing...)

Thanks a lot,

Michael

 

Re:Strange different behaviour between .BMP and jpeg-converted .BMP


i really didn't look at your code completely but you should be forcing
24 bit BMP formats just after you create  them before drawing your
Jpg on it. if your screen formation is lets say 16 bit then your BMP will
take on the format of your screen settings when you create them..
 so after you create your bitmap set the pixelformat before drawing any
data from the Jpeg..
  for example.,
  TBitmap *{*word*99} = new TBitmap();
  {*word*99}->Pixelformat = pf24bit;
 now do the rest.
 P.S.
    you should be deleting the "picture" object while your at it..
Quote
Michael wrote:
> Trying to use a function which is able to convert a TBitmap to another
> TBitmap, I got a different behaviour between the following to cases:

> 1) using a .bmp-file directly created from a standard graphics program
> 2) using a .jpg-file also directly created from a standard graphics
> program. This one I tried to convert inside BCB to a .bmp file and use
> it with the same function (see code-snippet below)

> Result:
>   tst0.bmp look quite similar in both cases 1) und 2)
>   tst1.bmp look quite different. The resulting picture's  right margin
> seems to have been cutted and it seems to have been stretched,

>  if(ExtractFileExt(article_filename)==".bmp") {
>     src_bitmap->LoadFromFile(article_filename);
>   }
>   else if(ExtractFileExt(article_filename)==".jpg")  {
>     TJPEGImage *src_jpg_image=new TJPEGImage;
>     src_jpg_image->LoadFromFile(article_filename);
>     src_bitmap->Width=src_jpg_image->Width;
>     src_bitmap->Height=src_jpg_image->Height;
>     src_bitmap->Canvas->Draw(0, 0, src_jpg_image);
>     TPicture *picture=new TPicture;
>     picture->Assign(src_bitmap);

>     TMemoryStream *mem_stream=new TMemoryStream();
>     picture->Bitmap->SaveToStream(mem_stream);
>     mem_stream->Position=0;
>     src_bitmap->LoadFromStream(mem_stream);
>     delete mem_stream;
>   }
>   else
>     return;

>   Graphics::TBitmap *dst_bitmap=new Graphics::TBitmap;

>   MY_FUNC(dst_bitmap, src_bitmap);

>   src_bitmap->SaveToFile("c:\\tst0.bmp");
>   dst_bitmap->SaveToFile("c:\\tst1.bmp");

> So my question: Is in the conversion in the .jpg-case an obvious
> error, so the resulting .bmp-file is a problematic one?

> Perhaps there is even a much more easier way to convert a jpeg-file's
> bitmap in a .bmp-bitmap. I tried it another way, but MY_FUNC()
> contains ScanLine(), which seems to last a half eternity to be
> executed for each line of a comperssed picture (, so I decided to
> convert it into a uncompressed bitmap for fast processing...)

> Thanks a lot,

> Michael

Re:Strange different behaviour between .BMP and jpeg-converted .BMP


I use the following method to convert a JPEG into a BMP file:
http://www.geocities.com/rodolfofrino/JPGToBMP_BMPToJPG.html

Rodolfo

Quote
> Perhaps there is even a much more easier way to convert a jpeg-file's
> bitmap in a .bmp-bitmap. I tried it another way, but MY_FUNC()
> contains ScanLine(), which seems to last a half eternity to be
> executed for each line of a comperssed picture (, so I decided to
> convert it into a uncompressed bitmap for fast processing...)

> Thanks a lot,

> Michael

Re:Strange different behaviour between .BMP and jpeg-converted .BMP


Quote
>I use the following method to convert a JPEG into a BMP file:
>http://www.geocities.com/rodolfofrino/JPGToBMP_BMPToJPG.html

With this conversion the resulting bitmap was correct.

Thanks,

Michael

P.S. For understanding-resons: it would be interesting why 'my'
methode produced such differnt results.  

Other Threads