473,765 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a subset of a Bitmap

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(Rectangl e(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_Drawin g_Image_Members .htm
Oct 3 '07 #1
2 2606
1 create an empby bitmap
2 use Graphics::FromI mage 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
--
Sheng Jiang
Microsoft MVP in VC++
"Peter Oliphant" <po*******@roun dtripllc.comwro te in message
news:OE******** ******@TK2MSFTN GP03.phx.gbl...
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(Rectangl e(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_Dra
wing_Image_Memb ers.htm
>

Oct 3 '07 #2
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==]

"Sheng Jiang[MVP]" <sh*********@ho tmail.com.discu sswrote in message
news:eO******** ******@TK2MSFTN GP05.phx.gbl...
>1 create an empby bitmap
2 use Graphics::FromI mage 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
--
Sheng Jiang
Microsoft MVP in VC++
"Peter Oliphant" <po*******@roun dtripllc.comwro te in message
news:OE******** ******@TK2MSFTN GP03.phx.gbl...
>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(Rectangl e(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_Dra
wing_Image_Memb ers.htm
>>

Oct 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7495
by: MiW | last post by:
Hi I'm making a kind of JavaScript-based library for creating SVG objects/elements. And I hit the wall... Every element (rect, circle etc.) can be created using *.createElement, then *.setAttribute and *.appendChild. Except "image" element. When 'image' element is created like this, it doesn't display anything. When I create that element with the same attributes in SVG code itself, it works perfectly. It works even if I create it with
0
2279
by: RHamilton | last post by:
I've been making stop and go progress on a test app that creates a .tif file. After fighting other problems (that have already been discussed here and elsewhere), I'm able to generate a .tif file that looks like it should, with the color depth it needs, and the compression scheme that it needs. The problem is that the app that comsumes the .tif requires tag 0x10a (Fill Order), and Bitmap.Save doesn't generate it by default. At this...
1
2616
by: James Dean | last post by:
In my program i create a 32ARGB bitmap. To actually create the bitmap seems very slow. In fairness the file size is very big. I support multiple bitmaps as well. I have to convert these bitmaps to thumbnails also which again seems very slow. There is a memory bitmap but i can't seem to find any good information about it. I want to be able to create a 32bpp bitmap as fast as possible and also try to make a thumbnail as fast as possible too....
3
1970
by: mark | last post by:
I want plot points on a cartesian surface with single pixels. I have been unable to find a graphics member which draws points. (Is there one?) I would like to create a bitmap one element wide and one element high where the element is black and use the drawimage method. I don't want to read the bitmap from a file. Is there a way to create this bitmap programmaticaly? --
7
2313
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they...
4
2756
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
0
1253
by: AlVis1515 | last post by:
We had a VB6 program that was used to take a scanned signature image as a set of screen coordinates. The VB6 program then converted this into a bitmap file which we used to embed the signature in certain documents such as invoices. The code was recently ported to VB.NET. We are using the BitMap and DataPoint objects to convert the data to a bitmap file, then saving it using a .NET PictureBox. The problem is that apparently the bitmap...
8
1501
by: Robert Dufour | last post by:
I been trying to look for samplecodes on how to create a simple tif file. I found a lot of commercial and stuff but I would prefer to roll my own. I only need to put some formatted text in a tif file so it can be faxed out. Does anyone now where I could find some sample source code. It can`t be all that big a secret :-) Regards, Bob
9
6560
by: colin | last post by:
Hi, I have all the components of a .bmp file in memory wich i need to write to a .bmp file, (or other convenient image file) ie i have 256 color pallete of RGBquads and array of 8bit pixels, I can create a System.Drawing.Bitmap and it allows me to set the witdh,height,bpp, and even the pixel data, but it doesnt seem to let me set the color palette, the palette property field is read/write but requires a...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.