Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / November 2007



Tip: Looking for answers? Try searching our database.

Insert smaller image into a bitmap

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
toes - 09 Nov 2007 13:22 GMT
I've got a Windows Forms project done in VB that creates graphs based
on data that is given to the program.  I can save those graphs as
bitmaps but now I want to be able to save multiple graphs in one
bitmap.  Is there a way to paste a smaller bitmap into a larger bitmap
by giving the coordinates that I want the image pasted into the larger
bitmap?

Brian
toes - 09 Nov 2007 13:25 GMT
I forgot to mention that I want to be able to store the image as a
jpg, gif or bitmap.  So I'm thinking that I want to insert the image
into either a graphics object or an Image object, not a bitmap object.
Dave O. - 09 Nov 2007 14:45 GMT
Read up on BitBlt and possibly StretchBlt, these calls will copy and in the
later case also resize an image from one container to another, as long as
both have a device context there should be no difficulty.

Dave O.

>I forgot to mention that I want to be able to store the image as a
> jpg, gif or bitmap.  So I'm thinking that I want to insert the image
> into either a graphics object or an Image object, not a bitmap object.
toes - 16 Nov 2007 17:45 GMT
> Read up on BitBlt and possibly StretchBlt, these calls will copy and in the
> later case also resize animagefrom one container to another, as long as
[quoted text clipped - 7 lines]
>
> - Show quoted text -

I'm running into some trouble getting BitBlt and StretchBlt to work
for me.  I declare the function in my form like the following:

Private Declare Auto Function StretchBlt Lib "GDI32.DLL" _
       (ByVal hdcDest As IntPtr, ByVal nXOriginDest As Integer, _
       ByVal nYOriginDest As Integer, ByVal nWidthDest As Integer, _
       ByVal nHeightDest As Integer, ByVal hdcSrc As IntPtr, _
       ByVal nXOriginSrc As Integer, ByVal nYOriginSrc As Integer, _
       ByVal nWidthSrc As Integer, ByVal nHeightSrc As Integer, _
       ByVal dwRop As Int32) As Boolean

What I'm having trouble with is getting three images pasted into one
larger image.  I have a function called drawDiagram() that creates my
graphs and returns them as a Graphics object.  I make an initial call
to StretchBlt with my first graph.  I think I then have to release the
HDC to my destination image.  The result of this is that my
destination image is wiped clean.  By the time I go to save my larger
destination image it is a plain white picture with no graphs located
on it.  I'm also having trouble getting StretchBlt to save my graphs
in different XY coordinates on the destination graph.  When I try to
StretchBlt just one graph in various places on the destination image
the graph always ends up at the top of the picture.  Finally, I'm sure
I'm not disposing of all the objects that I should, I would appreciate
any help here as well.  Here is my code:

ImageFile = New Bitmap(500, 660)
ImgFileGrphcs = Graphics.FromImage(ImageFile)
ImgFileGrphcs.FillRectangle(Brushes.White, 0, 0, ImageFile.Width,
ImageFile.Height)

If Color1.SelectedIndex = -1 Then
    colorIndex = 0
Else
    colorIndex = Color1.SelectedIndex
End If

SrcBitmap = drawDiagram(Cell1Image, Solution1.SelectedIndex - 1,
colorIndex)

Dim imghdc As IntPtr = ImgFileGrphcs.GetHdc
StretchBlt(imghdc, 0, 0, 500, 220, SrcBitmap.GetHdc, 0, 0, 500, 220,
SRCCOPY)
ImgFileGrphcs.ReleaseHdc(imghdc)

If Color3.SelectedIndex = -1 Then
  colorIndex = 0
Else
  colorIndex = Color3.SelectedIndex
End If

SrcBitmap.Dispose()

SrcBitmap = drawDiagram(Cell1Image, Solution3.SelectedIndex - 1,
colorIndex)

Dim imghdc2 As IntPtr = ImgFileGrphcs.GetHdc
StretchBlt(imghdc2, 0, 220, 500, 220, SrcBitmap.GetHdc, 0, 0, 500,
220, SRCCOPY)
ImgFileGrphcs.ReleaseHdc(imghdc2)

If Color5.SelectedIndex = -1 Then
  colorIndex = 0
Else
  colorIndex = Color5.SelectedIndex
End If

SrcBitmap.Dispose()

SrcBitmap = drawDiagram(Cell1Image, Solution5.SelectedIndex - 1,
colorIndex)

Dim imghdc3 As IntPtr = ImgFileGrphcs.GetHdc
StretchBlt(imghdc3, 0, 440, 500, 220, SrcBitmap.GetHdc, 0, 0, 500,
220, SRCCOPY)
ImgFileGrphcs.ReleaseHdc(imghdc3)

Brian
Thorsten Albers - 16 Nov 2007 23:40 GMT
toes <mcraven.2@wright.edu> schrieb im Beitrag
<01574b01-598e-43fc-9ba7-7ac2a1368a6f@s19g2000prg.googlegroups.com>...
> Private Declare Auto Function StretchBlt Lib "GDI32.DLL" _
>         (ByVal hdcDest As IntPtr, ByVal nXOriginDest As Integer, _
[quoted text clipped - 6 lines]
> ImageFile = New Bitmap(500, 660)
> ImgFileGrphcs = Graphics.FromImage(ImageFile)

>> I forgot to mention that I want to be able to store the image as a
>> jpg, gif or bitmap.

You also forgot to mention that you are using VB.NET. This newsgroup is
dealing with VB <= 6.0 aka 'classic'. Although both are called 'VB' they
are not the same and have only few things in common. You should ask your
question in a (VB).NET newsgroup.

Signature

----------------------------------------------------------------------
THORSTEN ALBERS                       Universität Freiburg
                                               albers@
                                                      uni-freiburg.de
----------------------------------------------------------------------

Thorsten Albers - 09 Nov 2007 18:26 GMT
toes <mcraven.2@wright.edu> schrieb im Beitrag
<1194614721.912593.228660@z24g2000prh.googlegroups.com>...
> I forgot to mention that I want to be able to store the image as a
> jpg, gif or bitmap.  So I'm thinking that I want to insert the image
> into either a graphics object or an Image object, not a bitmap object.

a) A picture object has a method called Render() which allows to draw the
picture to an object which provides a device context (DC), e.g. to a VB
picture box control.

PictureObject.Render -> Form|PictureBox|Printer.hDC

b) Some VB objects like a form, a picture box control, or a printer have a
method called PaintPicture() which allows to draw a given picture to the
object which provides the method.

Form|PictureBox|Printer.PaintPicture <- PictureObject

Some VB objects like e.g. a form or a picture box control have a Picture
property which provides the picture object associated with the object.

Signature

----------------------------------------------------------------------
THORSTEN ALBERS                       Universität Freiburg
                                               albers@
                                                      uni-freiburg.de
----------------------------------------------------------------------

Karl E. Peterson - 14 Nov 2007 00:15 GMT
> I forgot to mention that I want to be able to store the image as a
> jpg, gif or bitmap.  So I'm thinking that I want to insert the image
> into either a graphics object or an Image object, not a bitmap object.

You might also be very interested in this:

The FreeImage Project
http://freeimage.sourceforge.net/

Signature

.NET: It's About Trust!
http://vfred.mvps.org

 
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



©2009 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.