?
Solved

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

Posted on 2004-07-30
7
Medium Priority
?
494 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 7

Accepted Solution

by:
ramesh12 earned 2000 total points
ID: 11681120
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
ID: 11681303
I have to go to a meeting. But I will check code and see you tomorrow.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11686236
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 27

Author Comment

by:planocz
ID: 11693118
Hi ramesh12,
How are you defining  g from g.DrawImage?

0
 
LVL 27

Author Comment

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

Author Comment

by:planocz
ID: 11719531


        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
ID: 11745268
Oh I am sorry I did not open EE until today. Sorry for that.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

770 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