×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to print a jpg image? How to convert a jpg to bmp?

How to print a jpg image? How to convert a jpg to bmp?

How to print a jpg image? How to convert a jpg to bmp?

(OP)
The following code returns this error when it trys to print a jpg image: Cannot assign a TPicture to a Bitmap.void __fastcall TForm1::PrintphotoClick(TObject *Sender)
{
  unsigned int BitmapInfoSize, BitmapImageSize;
  long DIBWidth, DIBHeight;
  PChar BitmapImage;
  Windows::PBitmapInfo BitmapInfo;
  Graphics::TBitmap *Bitmap;
  Bitmap = new Graphics::TBitmap();
  TImage *pImage;
  pImage = Image1;
  Printer()->BeginDoc();
    Bitmap->Assign(pImage->Picture);
    GetDIBSizes(Bitmap->Handle, BitmapInfoSize, BitmapImageSize);
    BitmapInfo  = (PBitmapInfo) new char[BitmapInfoSize];
    BitmapImage = (PChar) new char [BitmapImageSize];
    GetDIB(Bitmap->Handle, 0, BitmapInfo, BitmapImage);
    DIBWidth  = BitmapInfo->bmiHeader.biWidth;
    DIBHeight = BitmapInfo->bmiHeader.biHeight;
    StretchDIBits(Printer()->Canvas->Handle,
                0, 0, DIBWidth, DIBHeight,
                0, 0, DIBWidth, DIBHeight,
                BitmapImage, BitmapInfo,
                DIB_RGB_COLORS, SRCCOPY);
    Printer()->EndDoc();
  delete [] BitmapImage;
  delete [] BitmapInfo;
  delete Bitmap;
}

So how do I print a jpg image that is in Image1?
pImage = Image1; prints if it is a bmp but not if it is a jpg.

And how do I convert a jpg to a bitmap?

Please help me out.

Thanks

RE: How to print a jpg image? How to convert a jpg to bmp?

Check out this link: www.bcbdev.com/faqs/faq89.htm . Also, they hve a couple more helps with JPEG's at their site. Do a search for JPEG or search through their FAQs and Articles.

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.

RE: How to print a jpg image? How to convert a jpg to bmp?

(OP)
Thanks James

But I still do not have my questions answered.
Please someone help me out.

Thanks,
Bob

RE: How to print a jpg image? How to convert a jpg to bmp?

Hi,

It's a good question and I'm facing the same problem as you. I'm afraid this is again a partial answer...

The problem is that the JPEG format is not a built-in standard in Windows. The conversion cannot be done by the system WIN32 itself.

Applications typically use some DLLs which provide the JPEG data handling features. Every single PC able to properly display a JPEG image certainly has at least one of such a DLL. It is fairly easy to locate one in your Windows/system directory.

The problem is that to make use of it you need to know the interface of the JPEG routines in it (i.e header file). What I'll do as soon as I have time is to investigate the assembly code of such a DLL, in order to find out the underlying routine format. Success is not guaranteed and it can take time.

On websites such as "programmer's heaven" (www.programmersheaven.com) you can find some free DLLs provided with the corresponding header files. (Once I found one named "jpegapi.dll"; however it pops up a nag screen...).

Let us know if you find out more ...

Woliwol

 

RE: How to print a jpg image? How to convert a jpg to bmp?

(OP)
Woliwol

I will figure it out, regardless of how long it takes. If I could figure out how to convert a JPG to a BMP I could make that work for me.

I found code that converts a BMP to JPG "if it works" have not tried it yet:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
  //Requires "jpeg.hpp" to be included in the source file
  TJPEGImage *jp = new TJPEGImage();
  try
  {
    jp->Assign(Image1->Picture->Bitmap);
    jp->SaveToFile("c:\\oneeye.jpg");
  }
  __finally
  {
    delete jp;
  }
}

Now to reverse the procedure?

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Graphics::TBitmap *bm = new Graphics::TBitmap();
  try
  {
    bm->Assign(Image1->Picture->Bitmap);
    //what should replace Bitmap? Because now it is a JPEG
    //that is loaded in Image1->Picture
    bm->SaveToFile("c:\\oneeye.bmp");
  }
  __finally
  {
    delete bm;
  }
}

I tried a simple conversion which does not work:

  Image1 has a JPEG in it.
  Image1->Picture->SaveToFile("C:\\temp.bmp");
  Image1->Picture->LoadFromFile("C:\\temp.bmp");

All this did was to change the file extension, the file was still a JPEG.

HELP, please.

Bob

RE: How to print a jpg image? How to convert a jpg to bmp?

(OP)
How to convert a JPG to a BMP.

I figured it out as follows which works perfect:

#include <jpeg.hpp> //has to be included in your .cpp file

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Graphics::TBitmap *bmp = new Graphics::TBitmap();
  TJPEGImage *jpg = new TJPEGImage();
  try
  {
    jpg->LoadFromFile("C:\\yourfile.jpg");
    jpg->DIBNeeded();
    bmp->Assign(jpg);
    Image1->Picture->Assign(bmp);
    Image1->Picture->SaveToFile("C:\\yourfile.bmp");
  }
    __finally
  {
    delete bmp;
    delete jpg;
  }
}

Now I can do anything I want with yourfile.bmp....like print it!

It may be the wrong way but it works perfect!

Bob

RE: How to print a jpg image? How to convert a jpg to bmp?

If it works it can't be all that wrong!

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.

RE: How to print a jpg image? How to convert a jpg to bmp?

I need to print a 24-bit bitmap file inside of a program that I'm writing in MSVC++ 6.0?  Any ideas?

RE: How to print a jpg image? How to convert a jpg to bmp?

(OP)
I do not use MSVC. But in Builder 5 here is a help file that may help you.

Indicates the bit format of the bitmap image, specifying how the image is displayed and how the pixels of the bitmap image are stored in memory.

enum TPixelFormat {pfDevice, pf1bit, pf4bit, pf8bit, pf15bit, pf16bit, pf24bit, pf32bit, pfCustom};
__property TPixelFormat PixelFormat = {read=GetPixelFormat, write=SetPixelFormat, nodefault};

Description

Use PixelFormat to change a TBitmap's internal image to a particular memory format and color depth, or to find out what memory format and color depth a TBitmap is using.

For example, PixelFormat can be used to set the pixel format of the bitmap image to 8-bit for video drivers that cannot display the native format of a bitmap image.

Changing the pixel format is most commonly used with ScanLine, because your code must decode the pixel data accessed by ScanLine. Image-editing tools usually use one pixel for all internal image operations and copy the results to the screen (in whatever format) as the last step.

*******************

Provides indexed access to each line of pixels.

__property void * ScanLine[int Row] = {read=GetScanline};

Description

ScanLine is used only with DIBs (Device Independent Bitmaps) for image editing tools that do low-level pixel work.

Example:

void __fastcall TForm1::Button1Click(TObject *Sender)

{
  Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
// This example shows drawing directly to the Bitmap
  Byte *ptr;
  try
  {
    pBitmap->LoadFromFile("C:\\Program Files\\Common Files\\Borland Shared\\Images\\Splash\\256color\\factory.bmp ");
    for (int y = 0; y < pBitmap->Height; y++)
    {
      ptr = (Byte *)pBitmap->ScanLine[y];
      for (int x = 0; x < pBitmap->Width; x++)

        ptr[x] = (Byte)y;
    }
    Canvas->Draw(0,0,pBitmap);
  }
  catch (...)
  {
    ShowMessage("Could not load or alter bitmap");
  }
  delete pBitmap;
}

Hope that helps you.



RE: How to print a jpg image? How to convert a jpg to bmp?

Hallo, ich möchte ein JGP mit der Auflösung 1600x1200 Pixel in ein JPG mit der Auflösung 360x270 Pixel umwandeln.
Wer hat eine Idee.

Danke Ralf

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close