Solved

Which component to inherit from?

Posted on 1999-01-13
11
196 Views
Last Modified: 2010-04-06
I am making a visual component that displays an image (that is to be edited).  I have made a separate component that holds the image data, and the new component will retrieve the data from that.

I have used TImage, with no luck.  It seems that the only way I can edit the image displayed is through the Canvas.  I want to avoid the Canvas property altogether, it is too slow.

I am using GetDIBits and SetDIBits to alter the contents of the image if necessary...the problem is, what do I use it ON?  Do it use them on TImage.Picture.Bitmap?  What I want to do is operate on the image displayed, that's it.

I do not want to use an already existing bitmap.  The image displayed in my component will be generated by itself, and will not be retrieved from any other source.  It seems that using Picture.Bitmap gives the user the option of loading a custom bitmap...I do not want to do that!!  It is not really important to stop that, since I will only be using the component for my own purposes, but I think I might be wrong in using Picture.Bitmap as the displayed image.

Is Image the wrong component to inherit from?  If it is, what would be better (in Delphi 2).  ALL I want is to make a component that can readily alter what it is displaying, AND contains he properties and methods of other visual components.  If Image is the best component to use, what property would I use as the bitmap of the displayed image?  Would there be any initialization necessary?  (I tried Picture.Bitmap := TBitmap.Create, but this didn't work).
0
Comment
Question by:scrapdog
  • 6
  • 3
  • 2
11 Comments
 
LVL 5

Author Comment

by:scrapdog
ID: 1356455
Bitmap := TBitmap.Create;

gives this error:   Object or class type required.
0
 
LVL 5

Author Comment

by:scrapdog
ID: 1356456
After some experimentation, I found that TCanvas has a handle.  Maybe I should pass Canvas.Handle to GetDIBits and SetDIBits...would this be an acceptable way?

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1356457
Hmm. You should use image1.picture.bitmap.handle for the DIB functions. Before that you should set bitmap.handleType:=bmDIB. The problem is: I'm not sure if the handleType property exists in Delphi2. It DOES exist in Delphi3/4.
Normally you can use image1.picture.bitmap.handle:=DIBHandle to change the image.

Hope this helps...

Regards, Madshi.
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 5

Author Comment

by:scrapdog
ID: 1356458
So Image.Canvas.Handle would not work?
0
 
LVL 5

Author Comment

by:scrapdog
ID: 1356459
I am rather desperate about this...I got my DrawGrid to work, but it was too slow with large images, so I scrapped it.  Now I am trying to use Image for drawing a grid, and I hit this little roadblock.

Hopefully I get this figured out, because it is starting to look like my only option is to do this whole project in DOS (d'oh!!)

I have yet to see a component for editing bitmaps in a grid...by any chance would you know of any?  The catch is, the pixel height and width must be changeable, since I will be using this grid to edit Commodore 64 sprites and character sets (where the pixels are twice as wide as they are tall).  Thanks in advance.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1356460
scrapdoc,

first, TPicture has already a valid TBitmap property. You don't need to create one. Just do a TPicture (Timage).LoadFromFile with a *.bmp and access its bitmap property.

As Madshi mentioned, there's a DIB type available under higher Delphi versions, but this isn't available for D2. Here might a new(er) API function be helpful. See win32.hlp for LoadImage. You can specify a resource or a file name and optinally create a dib section. The loadfromfile option is not supported under WinNT, though (says the help), but this might not be a problem for you. The loaded image cannot be assigned to TBitmap.Handle, though, under D2. You have to create a memory DC and select the bitmap handle returned by LoadImage into this. This way you have a valid DC and a valid DIB.

Hope this helps,

Ciao, Mike
0
 
LVL 5

Author Comment

by:scrapdog
ID: 1356461
Actually, I do not want to load a bitmap...I want to create a blank one.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1356462
Oops, sorry for that, I should have read your question more carefully. I believe for your purpose you cannot use one of the standard components (at least for manipulation). In order to always access the pixel data I'd recommend that you create a buffer (AllocMem etc.) whose content is then to be assigned to a standard bitmap by SetDIBits or SetDIBitsToDevice after each change. From my experience this is the fastest (and possibly only) way to accomplish the task without using a Delphi component.

Ciao, Mike
0
 
LVL 5

Author Comment

by:scrapdog
ID: 1356463
Yep, I am using a buffer...I created a separate non-visual component to act as the buffer.  My new component is meant to display the contents of the buffer.  I am sure I can get it to work fairly fast if I go through a standard bitmap, however I don't know how to create a blank one. :)  

Thanks for your help.  If you want, you can have the 25 points.
0
 
LVL 10

Accepted Solution

by:
Lischke earned 20 total points
ID: 1356464
I don't see the problem here. After you filled the buffer with 0's and assigned it to the bitmap you sould have the empty bitmap you want. OK, the dimensions must be known before you can create the bitmap, but that's the usual way (see Photoshop etc.).

Ciao, Mike
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1356465
Hi scrapdog, the canvas.handle is a DeviceContext handle, the bitmap.handle is a Bitmap handle. These are different handle types and a DIB handle is a bitmap handle. So please use this:
  Image1.picture.bitmap.handle:=YourDIBHandle;
That works (at least in Delphi3/4)...
If you want to delete the bitmap, you can use this:
  Image1.picture.bitmap.assign(nil);

Regards, Madshi.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to renew a Delphi rad-studio licence? 5 65
How to debug For loops? 3 49
Error E2158 compiling with Delphi XE10 Seattle 2 100
Twebbrowser add css to the header 3 25
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question