Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2007

Tip: Looking for answers? Try searching our database.

Creating a subset of a Bitmap

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Oliphant - 03 Oct 2007 22:02 GMT
I want to create a new Bitmap which is a portion of an existing Bitmap. For
example, if I have a Bitmap that is 100x100 in size I might want to create a
new Bitmap that is equivalent to the one located at (x,y)=(10,20)
(upper-left hand corner) and is 50x50 in size of the source Bitmap. A
sub-Bitmap if you will, sort of the equivalent to sub-strings for a source
string.

I don't think this works, but something like:

Bitmap^ src_bm =  gcnew Bitmap( "bm100x100.bmp" ) ;
Bitmap^ sub_bm = gcnew Bitmap( src_bm(Rectangle(10,20,50,50)) ) ;

Now I can do this via SLOW code ala creating the sub-bitmap of the proper
size and then copying pixels one-by-one from the source bitmap via GetPixel
and SetPixel. But I'm hoping that the construct for a sub-bitmap exists, as
it is quite natural. I can easily DRAW a sub-bitmap with the Graphics class,
but I want to create it as a new Bitmap.

Should I use the pixel-by-pixel method, or is there a faster and/or easier
way?

Thanx in advance for response!

[==Peter==]

PS - I'm developing in MS VC++ 2005 Express ala /cli (managed) code. This is
the Bitmap class I'm speaking of (since there may be more than one with the
same name but different namespaces):

ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/cpref8/html/T_System_Drawing_Image_Members.htm
Sheng Jiang[MVP] - 03 Oct 2007 22:51 GMT
1 create an empby bitmap
2 use Graphics::FromImage  to create a Graphics from the empby bitmap
3 draw the desired potion of your bitmap to the Graphics
4 save the bitmap you created at step 1 and altered in step 3
Signature

Sheng Jiang
Microsoft MVP in VC++

> I want to create a new Bitmap which is a portion of an existing Bitmap. For
> example, if I have a Bitmap that is 100x100 in size I might want to create a
[quoted text clipped - 24 lines]
> the Bitmap class I'm speaking of (since there may be more than one with the
> same name but different namespaces):

ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/cpref8/html/T_System_Dra
wing_Image_Members.htm
Peter Oliphant - 04 Oct 2007 01:37 GMT
Thanks, Sheng! I tried it and it works great!

Not only that, this opens up a lot more possibilities I hadn't considered,
since I didn't know before how to get a Graphics object from an Image
before! Thanks again!

[==Peter==]

>1 create an empby bitmap
> 2 use Graphics::FromImage  to create a Graphics from the empby bitmap
[quoted text clipped - 41 lines]
> ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/cpref8/html/T_System_Dra
> wing_Image_Members.htm

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.