Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Which component to inherit from?

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
scrapdog
Asked:
scrapdog
  • 6
  • 3
  • 2
1 Solution
 
scrapdogAuthor Commented:
Bitmap := TBitmap.Create;

gives this error:   Object or class type required.
0
 
scrapdogAuthor Commented:
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
 
MadshiCommented:
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
scrapdogAuthor Commented:
So Image.Canvas.Handle would not work?
0
 
scrapdogAuthor Commented:
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
 
LischkeCommented:
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
 
scrapdogAuthor Commented:
Actually, I do not want to load a bitmap...I want to create a blank one.
0
 
LischkeCommented:
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
 
scrapdogAuthor Commented:
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
 
LischkeCommented:
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
 
MadshiCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 6
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now