473,795 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cut out a region of a bitmap

Hello,

I have an bitmap in a resources file containing all icons displayed in
the toolbar. To display the icons I need to cut them out of the bitmap
and add them to an imagelist. The problem is the cutting out. I wrote
the following function:
[vb]
Public Shared Function CutOutIcon(ByRe f vBitmap As Image, _
ByVal iIndex As Integer) As Image

Try
Dim Bmp2 As Bitmap = New Bitmap(32, 32)
Dim GFX As Graphics = Graphics.FromIm age(Bmp2)
GFX.DrawImage(v Bitmap, 0, 0, New Rectangle(iInde x * 32,_
0, 32, 32), GraphicsUnit.Pi xel)
Return New Bitmap(32, 32, GFX)
Catch ex As Exception
End Try
End Function
[/vb]
vBitmap contains the pic from the resource (it really does, I checked
it). But all I get is a blank image.

What am I doing wrong?

Thanks in advance,
Stefan

--
_______________ _______________ _____www.VBTric ks.de.vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
_______________ _______________ _______________ ________
Nov 21 '05 #1
4 3363
Misinterpreted the syntax of the Bitmap constructor. So replace line
Return New Bitmap(32, 32, GFX) by Return Bmp2


Now I see something, but it's still not working correctly. The function
does not seem to cut out the right part. It cuts out only about 20x20
pixels and sizes it to 32x32. Must be something wrong with the dpi's...
Images 2 to 10 (iIndex 1 To 9) are empty as the first one before the
correction. The bitmap in the resources file has 75x75dpi.
Stefan

--
_______________ _______________ _____www.VBTric ks.de.vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
_______________ _______________ _______________ ________
Nov 21 '05 #2
put this outside orf trap
\\
end try
Return New Bitmap(32, 32, GFX)
end sub

regards

VBTricks.de.vu Webmaster wrote:
Hello,

I have an bitmap in a resources file containing all icons displayed in
the toolbar. To display the icons I need to cut them out of the bitmap
and add them to an imagelist. The problem is the cutting out. I wrote
the following function:
[vb]
Public Shared Function CutOutIcon(ByRe f vBitmap As Image, _
ByVal iIndex As Integer) As Image

Try
Dim Bmp2 As Bitmap = New Bitmap(32, 32)
Dim GFX As Graphics = Graphics.FromIm age(Bmp2)
GFX.DrawImage(v Bitmap, 0, 0, New Rectangle(iInde x * 32,_
0, 32, 32), GraphicsUnit.Pi xel)
Return New Bitmap(32, 32, GFX)
Catch ex As Exception
End Try
End Function
[/vb]
vBitmap contains the pic from the resource (it really does, I checked
it). But all I get is a blank image.

What am I doing wrong?

Thanks in advance,
Stefan

Nov 21 '05 #3
Hi Stefan,

Use the DrawImageUnscal ed method (GFX.DrawImageU nscaled(...)), as opposed to
the DrawImage method, and this should solve your problem!

-- Tom Spink

VBTricks.de.vu Webmaster wrote:
Misinterpreted the syntax of the Bitmap constructor. So replace line
Return New Bitmap(32, 32, GFX)

by
Return Bmp2


Now I see something, but it's still not working correctly. The function
does not seem to cut out the right part. It cuts out only about 20x20
pixels and sizes it to 32x32. Must be something wrong with the dpi's...
Images 2 to 10 (iIndex 1 To 9) are empty as the first one before the
correction. The bitmap in the resources file has 75x75dpi.
Stefan

Nov 21 '05 #4
This solved my problem:

Dim Bmp2 As Bitmap = New Bitmap(32, 32)
Dim GFX As Graphics = Graphics.FromIm age(Bmp2)
Dim sourceRect As Rectangle = New Rectangle(count * 32, 0, 32, 32)
Dim destRect As Rectangle = New Rectangle(0, 0, 32, 32)
GFX.DrawImage(v bitmap, destRect, sourceRect, GraphicsUnit.Pi xel)
Return Bmp2

Stefan

--
_______________ _______________ _____www.VBTric ks.de.vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
_______________ _______________ _______________ ________
Nov 21 '05 #5

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

Similar topics

5
1767
by: Martin Wolff | last post by:
Hi !! To draw multiple graphics objects which have different shapes, I’m using the region class to exclude/union the drawing area of these Objects. The rectangle around a single object is of the size of 80x80 pixels. So looping through these pixels and excluding the area of every transparent pixel, the region will be built. Afterwards, such an object has a memory usage of approx. 700Kb (before
2
1066
by: Brian Henry | last post by:
I can get an image into the MDI client region with the following code but it tiles, how can i make it center only? thanks Dim c As Control For Each c In Me.Controls If c.GetType.Name = "MdiClient" Then Dim b As Drawing.Bitmap b = New Drawing.Bitmap(GetType(frmMainWindow).Assembly.GetManifestResourceStream("bd b.reschlogo.png"))
2
2075
by: Willie jan | last post by:
Hi, i try to create a bitmap with transparent regions, but it does not work. the transparent region turns out to be black. anybody some ideas?? Dim bmap As Bitmap(100,100,Imaging.PixelFormat.Format32bppPArgb) Dim g As Graphics = Graphics.FromImage(bmap) g.Clear(Color.Transparent)
2
2519
by: Mark Denardo | last post by:
Hi, I need some expert GDI+ person to help me with my RoundOffImage Function: What I'm trying to do is take in an image, crop off the edges around an ellipse region I set up, and then return the cropped image from the function. I sort of have this working, but not thoroughly. If I take the output image of this function and draw it on my form it shows the clipped image as transparent as I am wanting it. But if I take that image and...
7
8243
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
14
11928
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was doing something was really inefficient and could reduce 10 lines of code with 2, etc. For reading, I am using a TcpClient and I call NetworkStream ns = client.GetStream(); to get a stream stream.Read(buffer, 0, buffer.Length);
3
1814
by: Manuel | last post by:
Hi to all, I have a System.Drawing.Graphics, I need to clip a region and put it in a different another Graphics with the size of clipped region. There's suggestion or a tutorial? Thanks in advice
8
4324
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the FromImage call will fail for indexed bitmaps.
3
3375
by: =?Utf-8?B?UnVieSBOYWRsZXI=?= | last post by:
Hi EveryOne, Does some one knows a way or tool that knows how to divide image into regions with c# so if the image is like a table style i will now the positions of the columns? i can read the pixlels colors but it will be very slow. thanks
0
9519
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
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
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...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.