Using TBitmap and TImage alternately (D2007)?

I have a QR code generator class available that has a constructor that
is called with a TImage as the parameter. The class will fill the
image with a QR code down the line. It was intended for use on a
visible form...

Now I want to use this in an application that prints a report and in
this application there is no image to use, instead it holds an
imagelist with preloaded QR codes which it transfers to the printer
canvas as follows:
{code}
var
  QR_BMP_SSM: TBitMap;
  ...
begin
  ...
  QR_BMP_SSM := TBitMap.Create;
  imlQR.GetBitmap(0, QR_BMP_SSM); //Read from imagelist
  ...
  if (LicType and 1) > 0 then  //SSM
  begin
    Rect.TopLeft.X := xm;
    Rect.TopLeft.Y := y + tdy;
    Rect.BottomRight.X := Rect.TopLeft.X + 3*xm div 2;
    Rect.BottomRight.Y := Rect.TopLeft.Y + 3*xm div 2;
    StretchDraw(Rect, QR_BMP_SSM); //Xfer QR to printer canvas
  end;
  ...
{code}

The QR class uses internally a TBitmap but it is created and destroyed
in the class itself, the assignment to the TImage object is done in
the end of QR code generation into the bitmap as follows (FImage is
the supplied TImage object from the caller):
{code}
procedure TQRcodeGen.ScaleImage;
var
  Scale: double;
begin
  FImage.Canvas.Brush.Color := clWhite;
  FImage.Canvas.FillRect(Rect(0, 0, FImage.Width, FImage.Height));
  if ((FQRCodeBitmap.Width > 0) and (FQRCodeBitmap.Height > 0)) then
  begin
    if (FImage.Width < FImage.Height) then
    begin
      Scale := FImage.Width / FQRCodeBitmap.Width;
    end else
    begin
      Scale := FImage.Height / FQRCodeBitmap.Height;
    end;
    FImage.Canvas.StretchDraw(Rect(0, 0, Trunc(Scale *
FQRCodeBitmap.Width), Trunc(Scale * FQRCodeBitmap.Height)),
FQRCodeBitmap);
  end;
end;
{code}

It seems a waste to make a TImage in my application just to use the QR
code class....

So my question is really if I can instead overload the constructor of
the QR code generator as follows:
{code}
    constructor Create(Img: TImage);overload;
    constructor Create(Bmp: TBitMap);overload;
{code}
And then in the two constructors set a flag to control weather to
operate directly on the external bitmap or to use the internal bitmap
followed by the ending transfer onto the TImage.

I tried to use the D2007 help to find out what if anything to look out
for when switching between TImage and TBitmap, but the help function
did not work. :( (see my previous post here).


---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572
0
Bo
7/10/2015 9:07:02 AM
embarcadero.delphi.ide 3925 articles. 0 followers. Follow

7 Replies
1368 Views

Similar Articles

[PageSpeed] 44
Get it on Google Play
Get it on Apple App Store

On Fri, 10 Jul 2015 02:07:02 -0700, Bo Berglund
<bo.berglund@nospam.com> wrote:

Simplifying things a bit by asking this instead:

Given a class defined with a constructor:

constructor Create(Img: TImage);

could I then overload this by having this declaration?

constructor Create(Img: TImage); overload;
constructor Create(Bmp: TBitmap); overload

What I want to accomplish is that the original use is retained as
before, but I want it also to be possible to create it with a
different call parameter as shown.

I have tried googling a bit and I found a different way by not naming
the new constructor Create at all but use a different name:

constructor Create(Img: TImage); overload;
constructor CreateBmp(Bmp: TBitmap); overload;

Will I be able to use either one to create the object?
Or will there be some problems down the line?

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572
0
Bo
7/10/2015 3:40:11 PM
On Fri, 10 Jul 2015 08:40:11 -0700, Bo Berglund
<bo.berglund@nospam.com> wrote:

>constructor Create(Img: TImage); overload;
>constructor CreateBmp(Bmp: TBitmap); overload;
>
Sorry, those should not be overloads since they have different
names...
constructor Create(Img: TImage);
constructor CreateBmp(Bmp: TBitmap);


---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572
0
Bo
7/10/2015 4:11:09 PM
Bo wrote:

> I have a QR code generator class available that has a constructor that
> is called with a TImage as the parameter.

That is overkill, since it is not utilizing TImage's capabilities.

> The QR class uses internally a TBitmap but it is created and destroyed
> in the class itself, the assignment to the TImage object is done in
> the end of QR code generation into the bitmap as follows (FImage is
> the supplied TImage object from the caller):

I would suggest an alternative solution.  Change the class to only accept 
a TBitmap and not a TImage at all.  For UI work, you can simply pass in the 
TImage.Bitmap property as the TBitmap to operate on.  Internally, TQRcodeGen.ScaleImage() 
is forcing the TImage to hold a TBitmap anyway (the TImage.Canvas property 
is only valid when TImage is holding a TBitmap), so you would not lose any 
existing functionality with this change.

> It seems a waste to make a TImage in my application just to use the QR
> code class....

All the more readon to get rid of the dependance on TImage altogether.

> So my question is really if I can instead overload the constructor of
> the QR code generator as follows:
<snip>
> And then in the two constructors set a flag to control weather to
> operate directly on the external bitmap or to use the internal bitmap
> followed by the ending transfer onto the TImage.

Too much complexity when the end result would be the same in both cases if 
you just eliminate the TImage logic completely.

-- 
Remy Lebeau (TeamB)
0
Remy
7/10/2015 5:45:48 PM
On Fri, 10 Jul 2015 10:45:48 -0700, Remy Lebeau (TeamB)
<no.spam@no.spam.com> wrote:

>TImage.Bitmap property as the TBitmap to operate on. 

Could not find a TBitmap as a TImage property (and the D2007 help
system sucks!)


---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572
0
Bo
7/13/2015 11:19:30 PM
Bo wrote:

> Could not find a TBitmap as a TImage property (and the D2007
> help system sucks!)

Sorry, I meant the TImage.Picture.Bitmap property.

-- 
Remy Lebeau (TeamB)
0
Remy
7/14/2015 1:33:52 AM
Bo Berglund wrote:

> Could not find a TBitmap as a TImage property (and the D2007 help
> system sucks!)

I suggest to use free "Custom help" plugin. (I use v.1.2 in 2007 and I
don't know if it works or helpful in later versions).

The plugin allows to search in help _much_ better, use old help files
(I use help from CB5), use external help resources form internet.

[IDE-Experte (2006,07,09,10,XE,XE2)] CustomHelp
http://www.delphipraxis.net/140957-%5Bide-experte-2006-07-09-10-xe-xe2-%5D-customhelp.html

Download
http://theunknownones.googlecode.com/svn/tags/Release/CustomHelp/

Videos: how to install and use effectively

Version 1.2
https://vimeo.com/7200411
Version 2.0
https://vimeo.com/15021497

--
Alex
0
Alex
7/14/2015 3:55:01 AM
Bo wrote:

> Could not find a TBitmap as a TImage property (and the D2007
> help system sucks!)

Sorry, I meant the TImage.Picture.Bitmap property.

-- 
Remy Lebeau (TeamB)
0
Remy
7/14/2015 10:55:14 PM
Reply:

Similar Artilces:

Is it posible to configure Delphi XE3 IDE to use Delphi 7 compiler/debuger
Hi! Like many other developer out there I have several project which has been developed with older version of Delphi (Delphi 7). Since theese projects rely on some components which are not compatible with newer versions of Delphi (no newer versions available) I'm forced to do any maintnance on theese projects using Delphi 7. Another solution would be to find replacment components which would provide me with same capabilities and work with latest versions of Delphi. But this would probbably require compleete rewritings of my projects (lots and lots of work). So currently I'm using...

To use or not to use Delphi
Sadly, it seems to me that there is a sort of race between the two threads, for and against using Delphi in new projects, with more or less the same users posting in both threads. Arguments are fiercely debated in both camps. Borland had their own vision. As a community, now that Delphi has changed ownership I believe we should try to be more consistent, more clear, and more articulate in what we expect from Embercadero in terms of Delphi. We can contribute to keeping Delphi alive and moving in the right direction. "Laurent Cocea" schrieb: > Sadly, it seems to me that there is a sort of race ... <snip> Some people go fishing, some go to the movies, some like to take long walks on the beach, and then some like to type their fingers bloody discussing totally irrelevant issues on public Newsgroups. And my wife likes to watch soap operas and follow posts from a forum where new-baked parents are discussing their kids-issues. Everyone needs a hobby :-) Regards, Danijel Laurent Cocea wrote: > Sadly, it seems to me that there is a sort of race between the two > threads They're essentially the same thread with a little more trolling in one than the other. Lots of free time over the holidays and all. I think the discussion in general is a good thing, though. Help remind people why a tool like Delphi is worth while, and maybe even shed some light on some of the things that still need attention. I still learn about ...

Delphi IDE running on Linux using WINE
Hi, I have recently retested the Delphi IDE on WINE and was surprised that it actually worked (there are issues however). Since I'd really like to use Delphi outside a VM on my Linux system, I decided to invest some time into this. I have now become the official maintainer of Delphi in the WINE appdb: https://appdb.winehq.org/objectManager.php?sClass=application&iId=42 Any other test results are welcome, I'm going to test all the Delphi versions I have access to in the near future. So far I know that Delphi XE3 and Delphi XE7 work. The installation is not strai...

Alternative to using USE in a PROCEDURE
is there a way to get around not using USE in a PROCEDURE? I need to because I have a main site that inserts information into other DB's that i use for various subdomains. But without being able to use USE i cant select which database is needed. thx in advance "Only when we are no longer afraid do we begin to live" -D. Thompson // f bush. ----------- "No man succeeds without a good woman behind him. Wife or mother, if it is both, he is twice blessed indeed." -Harold MacMillan should i use the master database and prefix my procedures with sp_? "Only when we are no longer afraid do we begin to live" -D. Thompson // f bush. ----------- "No man succeeds without a good woman behind him. Wife or mother, if it is both, he is twice blessed indeed." -Harold MacMillan Huh second time in 2 mins. Use the fully qualified path to the entity <database>.<owner>.<entity> ...

Is there a plan to rewrite the Delphi IDE using FireMonkey ?
I guess this should be a logical move to target multiple platforms and prove that Embarcadero is eating its own dog food. Although I think I've read somewhere that Delphi is using some Microsoft technology for the form designer but I might be wrong there. Is FireMonkey suitable for that kind of application or is the VCL still the way to go for "professional" business oriented applications ? What are your thoughts ? When XE2 is released I hope there will be a clear indication as to what kind of applications FireMonkey is suitable for or not. <John Riche> wrote in message...

Can I use a DataWindow OCX in Delphi IDE?
I've tried to use a DataWIndow OCX, but got a message i have no design-time license. Can I set up a license? Is it legal practice to use this OCX in different IDE then Power++? How can I obtain license number ? Thank You. Max. No, it is not legal to use the Datawindow OCX in any tool other than Powerbuilder, Power++ and PowerJ. It shouldn't even be possible. They've got it locked down. -- Jim Egan [TeamPS] Dealer Solutions, LLC Houston, TX ...

How to get the style of tabs used in Delphi 2010 IDE?
Hi, When you have a project open in the Delphi 2010, each unit has its own tab in the IDE. What component is being used for that? I don't think it is the standard TPageControl, or TTabControl, as those look a bit different. Each tab in the IDE has rounded corners, while the standard components have tabs with squared corners. Anyway, I am not that concerned about the look, but what I would really like to get is the little controls that appear on the right side of the IDE tabs group. If you have a few units (tabs) open, these controls on the right side consist only of a chevron poin...

Delphi IDE
I am using an external manifest file to support UAC elevations via the RC to RES technique. Once I do this, I have to add the Theme aware info to that manifest or I get resource warnings. To get rid of the warning, I uncheck the themes option on the project. This works fine, but the IDE shows the form designer as non-themed. When it the runs, it is themed, but not in the designer. I am using Delphi 2010, but I tried on Delphi XE3 with the same results. If I use the Delphi XE3 "Use custom manifest" option, it works fine. Is there a way to use an external manifest and still have the IDE show a themed form designer using Delphi 2010? Thanks. Isaac wrote: > I am using an external manifest file to support UAC elevations via the > RC to RES technique. > > Once I do this, I have to add the Theme aware info to that manifest Yes. If you use a custom manifest, you have to provide ALL manifest values that your app uses. At this time, Delphi is not able to merge multiple manifest sources into a single manifest resource (that would be a nice feature to have). > To get rid of the warning, I uncheck the themes option on the project. Yes, you must do that if you provide a custom manifest. > This works fine, but the IDE shows the form designer as non-themed. > When it the runs, it is themed, but not in the designer. Since the Form Designer runs within the IDE process, it should be using the IDE's theming, n...

Using Delphi 7 and Delphi 2010
I had a project in Delphi 7. I worked on it in Delphi 2010. When I try to open the .dpr again in Delphi 7, the IDE toolbar widens across both monitors, and Delphi 7 locks up. It appears that Delphi 2010 modifies the .dpr in a way that makes Delphi 7 unable to open it again. All my forms & units appear to open fine in D7 after D2010, except for the warnings on the ExplicitHeight and ExplicitWidth properties being missing... I can easily recreate the .dpr, but is this expected behavior? Thanks. Tom Field wrote: > I had a project in Delphi 7. > > I worked o...

delphi Win32 using delphi .NET dll
Hi, I'm trying to use a delphi.NET dll in delphi.WIN32. I am currently using CodeGear Delphi 2007 with version2(base version) of .NET I can get the dll to import into the WIN32 application the only problem is when i include things such as: "using Classes,DateUtils, SysUtils" in the .NET dll the win32 application will instantly hang when any of the dll functions are called. Any help would be great thanks. Also I have tried this example and it also crashes for me? http://cc.embarcadero.com/Item/22688 -Braden I also found this.. "The problem is that, wehn you instal...

How design a COM using Delphi and Using in PB7?
I need some component, So, we want using DELPHI5 to develop a COM or Activex. What type of knowege or Skill I must know it. Can anyone tell us? from DRAOGN Can you explain what type of component you want to create? You may not need to a) build your own, or b) use Delphi. If the component should be used from within a PB application, you ought to use PB to develop it unless it is something that PB does not let you do. regards, Bill DRAGON wrote: > I need some component, So, we want using DELPHI5 to develop a COM or > Activex. > What type of knowege or Skill I ...

VS ide / delphi ide key map
I'm quit lost in VS ide, F9 run, F8 / F7 Ctrl+Alt+P for tool pallet and the fast find when you type component name F11 to switch to code view / object inspector, the ability to navigate in the object inspector with tab and writing property name. Will someone make a Delphi to VS guide? -- Henning Swiboda wrote: > I'm quit lost in VS ide, F9 run, F8 / F7 > Ctrl+Alt+P for tool pallet and the fast find when you type component > name > F11 to switch to code view / object inspector, the ability to navigate > in the object inspector with tab and writing propert...

How to use a delphi XE3 obj file in delphi 2007?
Hi, I'm migrating an application from delphi 2007 to delphi XE3 and I would like to do it in several steps. To do this I need to use a part of my new code (XE3) in the current delphi 2007 application. So I want to use the .obj file from my XE3 file. I know I have to use the {$L 'Filename'} and I know that I have to declare the functions that I want to use in external in my D2007 project. I wanted to make an easy and simple example to see how it works with only 1 function 'hello world' compiled in obj with XE3 but I can't find the way to use it in D2007. In D200...

can i use delphi 2007 bpls in delphi 2009
can i use delphi 2007 bpls in delphi 2009 ? "Gaetan SIRY" skrev i meddelelsen news:8703@forums.codegear.com... > can i use delphi 2007 bpls in delphi 2009 ? No. -- Finn Tolderlund The compatiblity between D2006 and D2007 was unique. Normaly they can't be compatible because new version enhance/change the API. And D2009 defines String = Unicode where older version has String = Ansistring so D200x/Dx-BPL are 200% incompatible with D2009. ...

Delphi 2006 vs Delphi 2009 IDE stability
Hello, all. I have medium sized project which includes about 20Mb of source code (just size of *.pas files). I use Delphi 2006. There are third party component suites JVCL, DevExpress Bars, Pegasus Imaging. All updates applied. The main problem is IDE stability. About four..five times a day IDE become unstable after intensive usage of code insight functions (most often I press Ctrl+Space key). The best outcome is that I have to save everything and restart the IDE. The worst outcome is when IDE stalls or falls into endless loop of error messages and any unsaved work is lost. OS...

If you use Delphi...
If you use Delphi for .NET with ASA, please vote for this: http://qc.borland.com/wc/qcmain.aspx?d=31677 ...

Comparison between Visual Studio 2008 IDE and Delphi 2010 IDE?
Hi, I wonder which is more programmer friendly. Especially for syntax highlighting and fast code writting, viewing.. Thanks.. Mehmet Fide wrote: > Hi, > > I wonder which is more programmer friendly. Especially for syntax > highlighting and fast code writting, viewing.. > > > Thanks.. See "RAD Studio 2010 vs. Visual Studio 2010" in non-technical group. -- Warm Regards, Lee ...

When to use ( and when to use ((?
I'm just not getting it. When do you use ( in a statement, when do you need to use ((, and is the space after either or both mandatory? For example, I coded this statement: if (( $_ eq $bad_guys_ip )) { more_stuff_here }; Why the two (( in an if? And why does it seem to not work when I miss the space after the ((? Thanx! Mark me as... /Corn-fused|Dense/ > I'm just not getting it. >=20 > When do you use ( in a statement, when do you need to use ((, and is > the space after either or both mandatory? >=20 > For example, I coded this sta...

TBitmap and TImage
I need to display a bitmap image. In some cases I want to display the entire image but sometimes I need to display the rightmost part of it. I use a TImage and a TBitmap which are fields of the form. I clearly miss something because the following code does not work. After starting the program if I first click Button1 then Button2 it's OK, but if I start the program and I first click Button2, then I get a truncated image when I click Button1. The right part of the image is missing. What am I doing wrong? procedure TForm1.FormCreate(Sender: TObject); begin bmp := TBitmap...

MOVED: Use Delphi XE TLB importer in Delphi 2007?
....to the ActiveX group: https://forums.embarcadero.com/thread.jspa?threadID=47170 -- Craig Stuntz · Vertex Systems Corp. · Columbus, OH Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz/ ...

Delphi IDEs
Is it possible to write applications for Android and touch sensitive screens with Delphi XE4 or later versions of Delphi? Is it possible to write applications for Windows 8 and touch sensitive screens with Delphi XE4 and later versions of Delphi? Pier Pier wrote: > Is it possible to write applications for Android and touch sensitive > screens with Delphi XE4 or later versions of Delphi? iOS support was added in XE4. Android support was added in Delphi XE5. > Is it possible to write applications for Windows 8 and touch sensitive > screens with Delphi XE4 an...

Using Using
I have just completed reading a chapter in my book on performance. The books says to speed up performance on your web site you should use the using statement when opening connections. My question is how do you catch errors if you are using this as apposed to a try catch block.thanksBryan  Why would you use it as an alternative to a try/catch statement. Couldn't you just do something like  public void UsingSomeMethod() { try { SomeMethod(); } catch(SomeException e) { /// do something useful }}public void SomeMethod() { using (Something) { /// do something }}  public void SomeMethod()  {    using (Something)     {        try {}       catch(SomeException e) {}    }} Hi,So what is the actual benefit of using the using statement if you still have to put it in a try catch to catch errors, I thought that was the point of using using... to get away from the try catch which is apparently more of a memory chomper. Will it really speed up my apps then? The only benefit i can see it that you dont have to explicitly close your connection which would free up some memory there.Bryan   First of all there are two things, using Statement and using directive, I think you are referring to the 'using' statement. The using statement allows the programmer to specify when objects that use resourc...

How to use AppModeler to generate Delphi forms using Cached Updates
<HTML> <TT>A beginner's question regarding AppModeler 6.1, Delphi 3, and Interbase 5.x...</TT> <P><TT>While I am impressed with the amount of thought and work that has gone into AppModeler, I have nonetheless been surprised to discover that the Delphi application generated by AppModeler is not suitable for real-world situations because of the "fly-away" problem afflicting newly-entered records.</TT> <P><TT>When I enter a record on an AppModeler-generated Delphi form, the record disappears ("flies away") immedia...

How to use a .dmp file for a system which crashes using a delphi app
Hi, I put this post here because I am not sure of the best location. I have been given a memory dump (.dmp) file by a client who thinks that a Delphi 7 application is causing their system to blue screen from time to time. Does anyone know how I can use this .dmp file to locate the problem in the delphi app? The build the client is using has debug symbols turned on. I have downloaded Microsoft Debugging Tools for windows and have dupmchk.exe (and kd.exe) but I would really appreciate some help with how these or any other useful tools should be used? Many thanks Ben > I have downloaded Microsoft Debugging Tools for windows and have dupmchk.exe (and kd.exe) You'd have to learn how to use WinDbg, which is a little too complex to explain here. Anyway you can start by opening the .dmp file and follow what WinDbg tell you, it will point you to the executable and stack trace that led to the error. At least you'll understand what is exactly causing the BSOD. Delphi debug symbols are not useful because they are in a differend format than those used by MS tools. You'd have convert them to a suitable format. It's a pity Delphi can't output debug informations in those formats. Anyway I believe it is a little strange a "normal" Delphi app can lead to a BSOD, because it usually require some kernel-side error. But without knowing what error and where it happens is hard to tell. Am 14.11.2011 11:20, schrieb Ben Russell: > Hi, I put t...

Web resources about - Using TBitmap and TImage alternately (D2007)? - embarcadero.delphi.ide

Jodi Arias Trial: Opening statements paint victim as alternately devout and violent
Jodi Arias is accused of shooting Travis Alexander in the face, stabbing him 27 times and slitting his throat in his Mesa home in June 2008

Ukraine, US to Alternately Cajole, Threaten Russia
Economic Times Ukraine, US to Alternately Cajole, Threaten Russia ABC News Ukraine is hoping to placate Russia and calm hostilities with its ...

Alternately, UPHOLSTERY NERDS HALP
I think I know what kind of seat, loosely speaking, I want in the Ranchero. It's the as-equipped-in-CJ5 Tuxedo Park -split bench like this:

Oculus Rift headset: Alternately thrilling and nauseating
Prepare for a disorienting virtual-reality future by seeing how our staff reacts to the Oculus Rift headset.

Off-B’way review: ‘34th Marathon of One-Act Plays: Series C’ alternately fun and icky - NYPOST.com
There’s a serious “ick” factor at the final roundup of Ensemble Studio Theater’s “34th Marathon of One-Act Plays.” From the elderly gentleman ...

Oculus Rift headset: Alternately thrilling and nauseating
Prepare for a disorienting virtual-reality future by seeing how our staff reacts to the Oculus Rift headset.

Instapundit » Blog Archive » DESCRIPTION: “Alternately depressing and terrifying.” WaPo: How the Obama ...
DESCRIPTION: “Alternately depressing and terrifying.” WaPo: How the Obama White House runs foreign policy. Even the Obama-friendly Washington ...

Ukraine, US to alternately cajole, threaten Russia
GENEVA (AP) — Ukraine is hoping to placate Russia and calm hostilities with its neighbor even as the U.S. prepares a new round of sanctions to ...

Ukraine, U.S. To Alternately Cajole, Threaten Russia
Diplomats from Ukraine, the U.S., the European Union and Russia are meeting in Geneva Thursday for the first time over the burgeoning crisis ...

Farewell, App Store? Netizine Turns Magazines Into Social Networks, Runs On HTML5
... to HTML5 for them, wrap the social layer around the content, and return to them, in a couple of hours, their brand wrapped in social. Alternately, ...

Resources last updated: 3/8/2016 10:23:10 PM