Solved

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

Posted on 2004-07-30
7
470 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
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net 2 43
DataGridView does not show data rows correctly in vb.net 2013 3 39
VB.net/WinForms: adjust Screen Resolution 6 58
Complex SQL statement in VB.NET 7 14
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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