Solved

Which component to inherit from?

Posted on 1999-01-13
11
203 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 57
Delphi application Soap connection 5 120
Slow Restore if incremental backups using RDiff.exe 4 30
Microsoft Access 97 and Delphi XE2 9 54
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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