VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 12345[6]78910 ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 08:01:20 03/06/02 Wed
Author: Michel
Subject: Re: C++ Problem with Crop
In reply to: Erik 's message, "Re: C++ Problem with Crop" on 05:13:10 03/06/02 Wed


Hi Erik,

Thanks for the note about the html in the forum. I have removed "html allowed" in the forum options.

If you remove the dynamic_cast you will receive a memory exception when the graphic loaded in TImage is not a class derived from TDibGraphic. Below is the code (the >< should be fine) and I will also email my sample project.

Make sure you add EnReg.Pas to your project.

Best regards,

Michel

>Hi Michel,
>
>thank you very much for the fast reply.
>First of all the code is not properly displayed in the
>forum think the "> < " is seen as html tags and cut
>out of the posting.
>Second ;)
>Your "better approach" is exactly what I need ;)
>But somehow it doesnt work ;(
>
> TDibGraphic* Graphic = dynamic_cast..........
>
>is always null (Image->Picture->Graphic has a value)
>
>if I say
>TDibGraphic* Graphic =
>(TDibGraphic*)(Image->Picture->Graphic);
>
>Graphic has a value but Apply causes a Memory
>Violation.
>
>Thanks
>
>Erik
>
>
>
>>
>>Hi Erik,
>>
>>There is a few things I would look at here:
>>
>>Before trying to obtain the TDibGraphic from
>>TImage->Picture->Graphic make sure the graphic
>>contained is really a TDibGraphic. For example, it may
>>be a TBitmap loaded. To check this, save the return
>>value of
>>TImage->Picture->Graphic.ClassName() to a variable and
>>view it in the debugger. If it is not a class derived
>>from TDibGraphic, make use you do "Add to Project" the
>>EnReg.Pas unit to register the Envision formats. Also
>>check the Envision.Inc file to enable the Envision
>>bitmap support if desired.
>>
>>In,
>>
>>TDibGraphic *Gr =new TDibGraphic();
>>Image1->Picture->Graphic->SaveToStream(strm);
>>Gr->NewImage(320,280,ifTrueColor,0,0,0);
>>Gr->LoadFromStream(strm);
>>
>>You should create the appropriate TDibGraphic derived
>>class, not the base TDibGraphic class, which does not
>>implement LoadFromStream. Also, the NewImage call is
>>not necessary because LoadFromStream will take care of
>>setting the size.
>>
>>For example,
>>
>>Gr = new TBitmapGraphic();
>>
>>for a BMP file.
>>
>>Here is a better approach to crop the contents of a
>>TImage->Picture->Graphic:
>>
>>void __fastcall TForm1::CropBtnClick(TObject *Sender)
>>{
>> TDibGraphic* Graphic =
>>dynamic_cast<TDibGraphic*>(Image->Picture->Graphic);
>>
>> if (Graphic!=NULL)
>> {
>> // Graphic is a TDibGraphic
>> TCropTransform* Transform = new
>>TCropTransform;
>> try
>> {
>> Transform->Left = 20;
>> Transform->Right = 20;
>> Transform->Top = 20;
>> Transform->Bottom = 20;
>>
>>Transform->Apply((TDibGraphic*)Image->Picture->Graphic
>)
>>;
>>
>> Image->Invalidate();
>> }
>> __finally
>> {
>> delete Transform;
>> }
>> }
>>}
>>
>>Best regards,
>>
>>Michel
>>
>>
>>
>>
>>
>>
>>
>>>Hello I have a TImage and i want to
>>>crop it.
>>>I tried to do it similar like the sourcecode
>>>of the delphi example.
>>>I got several Memory errors when I tried to
>>>map the TImage->Picture->Graphics to TDibGraphic.
>>>I didnt find a solution for that so I tried to
>>>solve the whole think using stream.
>>>This worked fine except that the
>>>TDibGraphic->Height and ->Width were zero
>>>therefore the crop didnt work.
>>>
>>>You would do me great favour if you could send
>>>me a small C++ sniplet how to use it correctly.
>>>
>>>Thanks
>>>
>>>Erik
>>>
>>>
>>>
>>> Image1->Picture->LoadFromFile(FileName);
>>>
>>> TMemoryStream *strm=new TMemoryStream();
>>> TCropTransform *Transform = new TCropTransform();
>>> TDibGraphic *Gr =new TDibGraphic();
>>> Image1->Picture->Graphic->SaveToStream(strm);
>>> Gr->NewImage(320,280,ifTrueColor,0,0,0);
>>> Gr->LoadFromStream(strm);
>>>
>>> Transform->Left =75;
>>> Transform->Right =75;
>>> Transform->Top =25;
>>> Transform->Bottom =25;
>>> Transform->ApplyOnDest(Gr,Gr);
>>> Gr->SaveToStream(strm);
>>>
>>Image1->Picture->Graphic->LoadFromStream(strm);
>>> delete Transform;
>>> delete Gr;
>>> delete strm;

[ Next Thread | Previous Thread | Next Message | Previous Message ]

[ Contact Forum Admin ]


Forum timezone: GMT-5
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.