Mega Code Archive

 
Categories / Delphi / Graphic
 

TJPEGImage to TBitMap conversion by assignment W XP Problem

Title: TJPEGImage to TBitMap conversion by assignment W XP Problem Question: Ive gotten an exception in JPEG to BitMap assignment and vice versa that is appearing all the time that I try to assign a TPEGImage to a TBitMap and the other way too, when I try to assign a TBitMap to a TJPEGImage. The exception message is "Cannot assign a TJPEGImage to a TBitMap". The most amazing thing is that, once, before I save to clippboard one image that was stored in databank, the assignment to TJPEGImage and to TBitMap was working well. Anyone has any idea of what is happening and a way to solve this problem? I don't have problems with the storage of the images in database, but few steps before, in debug scenario, I could find the exception point in the Assignment Methods of TJPEGImage and of TBitMap.However, the bmpImg.Assign(jpgImg) and jpgImg.Assign(bmpImg) have worked well before. And there was no problem with this kind of assignment. But after programming and test in Delphi a feature to call Adobe Photoshop by OLE automation and paste to clippboard one image retrived from the firebird databank, this exception of assignment began to appear for all the ways I try to convert images? What is possibly happening? Answer: The Code which I catch the exception is: var stImagem: TFileStream; stMemImg: TMemoryStream; bmpImg : TBitMap; grphImg : TJPEGImage; //img : TImage; begin grphImg := TJPEGImage.Create; bmpImg := TBitMap.Create; //img := Timage.Create(self); stImagem := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); stMemImg := TMemoryStream.Create; Try stImagem.Position := 0; if AnsiCompareStr(UpperCase(Copy(FileName, Length(FileName) - 2, 3)), UpperCase('bmp')) = 0 then bmpImg.LoadFromStream(stImagem) else begin grphImg.LoadFromStream(stImagem); //grphImg.LoadFromFile(FileName); //grphImg.Performance := jpBestSpeed; //grphImg.DIBNeeded; //grphImg.CompressionQuality := 1 {Nombre de 1 a 100}; grphImg.SaveToStream(stImagem); //grphImg.DIBNeeded; //grphImg.Smoothing := True; //bmpImg.Width := grphImg.Width; //bmpImg.Height := grphImg.Height; //bmpImg.Canvas.Draw(0,0, TGraphic(grphImg)); //bmpImg.FreeImage; bmpImg.Assign(grphImg); // Here where the Exception occurs ********** //img.Picture.Bitmap.LoadFromStream(stImagem);; //img.Picture.Bitmap.SaveToStream(stMemImg); end; bmpImg.SaveToStream(stMemImg); stMemImg.Position := 0; SLSIBdtstImagemOSIMAGEM.LoadFromStream(stMemImg); Finally stImagem.Free; stMemImg.Free; grphImg.Free; bmpImg.Free; End; end;