Solved

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

Posted on 2004-07-30
7
477 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

789 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