Solved

Looking for code to append or save two or more Bmps together.

Posted on 2004-07-30
7
450 Views
Last Modified: 2012-08-13
I have searched and can only find a saveadd to tiff. Looking for a way to add or append or something; to save two or more Bmps  or jpegs together. Working in VB.Net.
0
Comment
Question by:planocz
  • 4
  • 2
7 Comments
 
LVL 7

Accepted Solution

by:
ramesh12 earned 500 total points
Comment Utility
dim imgFile1 as image= Bitmap.FromFile(yourFileName1)
dim imgFile2 as image=Bitmap.FromFile(yourFileName2)

imgFile1=fixedsize(imgFile1,320,240)
imgFile2=fixedsize(imgFile2,320,240)


dim imgOut as image = New Bitmap(2 * imgFile1.Width, imgFile1.Height)
 
If Not imgFile1 Is Nothing Then g.DrawImage(imgFile1 , New Rectangle(0, 0, imgFile1.Width, imgFile1.Height), New Rectangle(0, 0, imgFile1.Width, imgFile1.Height), GraphicsUnit.Pixel)
If Not imgFile1  Is Nothing Then g.DrawImage(imgFile2, New Rectangle(imgFile1.Width, 0, imgFile2.Width, imgFile2.Height), New Rectangle(0, 0, imgFile1.Width, imgFile1.Height), GraphicsUnit.Pixel)


imgOut.Save(to your required place (either stream or file), ImageFormat.Jpeg)

    Private Function FixedSize(ByVal imgPhoto As Image, ByVal Width As Integer, ByVal Height As Integer) As Image
        Dim sourceWidth As Integer = imgPhoto.Width
        Dim sourceHeight As Integer = imgPhoto.Height
        Dim sourceX As Integer = 0
        Dim sourceY As Integer = 0
        Dim destX As Integer = 0
        Dim destY As Integer = 0

        Dim nPercent As Single = 0
        Dim nPercentW As Single = 0
        Dim nPercentH As Single = 0

        nPercentW = (CType(Width / CType(sourceWidth, Double), Double))
        nPercentH = (CType(Height / CType(sourceHeight, Double), Double))
        If nPercentH < nPercentW Then
            nPercent = nPercentH
            destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2)
        Else
            nPercent = nPercentW
            destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2)
        End If

        Dim destWidth As Integer = CType((sourceWidth * nPercent), Integer)
        Dim destHeight As Integer = CType((sourceHeight * nPercent), Integer)
        Dim bmPhoto As Bitmap
        bmPhoto = New Bitmap(Width, Height, PixelFormat.Format24bppRgb)
        bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)

        Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
        grPhoto.Clear(Color.White)
        grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic

        grPhoto.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth, destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel)

        grPhoto.Dispose()
        Return bmPhoto
    End Function
0
 
LVL 27

Author Comment

by:planocz
Comment Utility
I have to go to a meeting. But I will check code and see you tomorrow.
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Try this One:

Private Sub cmdAppend_Click()
    Dim strOrigFile, strAppendFile As String
    Dim lngPgCount As Long
    'This is the displayed image to which we are appending.
    ImgAdmin1.Image = "D:\image2\original.tif"
    'Because we are using the dialog box to pick the file for append,
    'we need to save the original file.
    strOrigFile = ImgAdmin1.Image
    ImgAdmin1.DialogTitle = "Select the file to be appended to the
        displayed image"
    ImgAdmin1.ShowFileDialog OpenDlg
    strAppendFile = ImgAdmin1.Image
    'Restore the original filename to the Image property because
    'the property must contain the destination file name.
    ImgAdmin1.Image = strOrigFile
    'Append 3 pages starting with page 1.
    ImgAdmin1.Append strAppendFile, 1, 3
End Sub

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/3rdparty/html/iac_method_append_example.asp

Regards,

Aeros
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 27

Author Comment

by:planocz
Comment Utility
Hi ramesh12,
How are you defining  g from g.DrawImage?

0
 
LVL 27

Author Comment

by:planocz
Comment Utility
Hi ramesh12,
I am still waiting on your response.
0
 
LVL 27

Author Comment

by:planocz
Comment Utility


        dim imgOut as image = New Bitmap(2 * imgFile1.Width, imgFile1.Height)
        Dim g As Graphics = Graphics.FromImage(imgOut)    '<------********

 ****  I am not happy that you left this part of the code out of your post.
It took me 3 days the search your different codes on the internet to find the missing link.
But all in all  you do get the points.


   
0
 
LVL 7

Expert Comment

by:ramesh12
Comment Utility
Oh I am sorry I did not open EE until today. Sorry for that.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

16 Experts available now in Live!

Get 1:1 Help Now