Solved

Which component to inherit from?

Posted on 1999-01-13
11
185 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now