Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
arunredi  
#1 Posted : Tuesday, March 31, 2009 1:58:23 PM(UTC)
arunredi

Rank: Newbie

Groups: Member
Joined: 6/18/2008(UTC)
Posts: 2

Hi,

I'm trying to build a web application where in I need to overlay multiple images onto one background for which I'm using combiner.ApplyMaskTransform function.

Everytime, when I try to do so, the system runs into 100% CPU usage and takes close to 3-4 minutes to combine the images. Is this normal? If not could anyone point me what I need to change to have the process completed faster.

Below is my code:
'Background image.
Dim background As New Aurigma.GraphicsMill.Bitmap(str)
'Mask.
Dim mask As New Aurigma.GraphicsMill.Bitmap(strMask)
'Create the transform.
Dim combiner As New Aurigma.GraphicsMill.Transforms.Combiner
combiner.CombineMode = Aurigma.GraphicsMill.Transforms.CombineMode.Copy

'Photos for the collage.
Dim photo1 As New Aurigma.GraphicsMill.Bitmap(usrFileName)
combiner.SourceBitmap = photo1

' m_num is the number of the images that need to be overlayed. values are read from database
Dim i As Integer
For i = 0 To (m_num -1)
'Combine with the image.
combiner.SourceRectangle = New System.Drawing.RectangleF(0, 0, photo1.Width, photo1.Height)
combiner.DestinationRectangle = New System.Drawing.RectangleF(hold_x.Item(i), hold_y.Item(i), hold_wd.Item(i), hold_ht.Item(i))
combiner.ApplyMaskTransform(background, mask)
Next
tmpFile = fileUploadPath & "\Temp\" & GetTempFileName() & "_collage.jpg"
background.Save(tmpFile)


Thanks in advance,
Arun
ChingYen  
#2 Posted : Tuesday, March 31, 2009 10:55:23 PM(UTC)
ChingYen

Rank: Advanced Member

Groups: Member
Joined: 3/3/2008(UTC)
Posts: 185

Thanks: 8 times
Hi,

You may try this method. It was given as sample by Aurigma Engineer last time. :)

Code:
    Private Function ManualCombine(ByVal image As Aurigma.GraphicsMill.Bitmap, ByVal mask As Aurigma.GraphicsMill.Bitmap) As Aurigma.GraphicsMill.Bitmap
        If image.Width <> mask.Width Or image.Height <> mask.Height Then
            Throw New ArgumentException("image")
        End If
        If image.PixelFormat <> PixelFormat.Format24bppRgb Then
            'Throw New ArgumentException("image")
            image.ColorManagement.Convert(PixelFormat.Format24bppRgb)
        End If
        If mask.PixelFormat <> PixelFormat.Format8bppGrayScale Then
            Throw New ArgumentException("mask")
        End If


        Dim result As New Aurigma.GraphicsMill.Bitmap(mask.Width, mask.Height, PixelFormat.Format32bppArgb)
        result.VerticalResolution = image.VerticalResolution
        result.HorizontalResolution = image.HorizontalResolution

        Dim imageData As Aurigma.GraphicsMill.BitmapData = image.LockBits()
        Dim maskData As Aurigma.GraphicsMill.BitmapData = mask.LockBits()
        Dim resultData As Aurigma.GraphicsMill.BitmapData = result.LockBits()

        Dim srcScan(imageData.Stride) As Byte
        Dim dstScan(resultData.Stride) As Byte
        Dim maskScan(maskData.Stride) As Byte

        Try
            For i As Integer = 0 To resultData.Height - 1
                Marshal.Copy(New IntPtr(imageData.Scan0.ToInt32() + i * imageData.Stride), srcScan, 0, imageData.Stride)
                Marshal.Copy(New IntPtr(resultData.Scan0.ToInt32() + i * resultData.Stride), dstScan, 0, resultData.Stride)
                Marshal.Copy(New IntPtr(maskData.Scan0.ToInt32() + i * maskData.Stride), maskScan, 0, maskData.Stride)

                Dim srcChannelIndex As Integer = 0
                Dim dstChannelIndex As Integer = 0
                For j As Integer = 0 To resultData.Width - 1
                    dstScan(dstChannelIndex) = srcScan(srcChannelIndex)
                    dstChannelIndex += 1
                    srcChannelIndex += 1
                    dstScan(dstChannelIndex) = srcScan(srcChannelIndex)
                    dstChannelIndex += 1
                    srcChannelIndex += 1
                    dstScan(dstChannelIndex) = srcScan(srcChannelIndex)
                    dstChannelIndex += 1
                    srcChannelIndex += 1
                    dstScan(dstChannelIndex) = maskScan(j)
                    dstChannelIndex += 1
                Next

                Marshal.Copy(dstScan, 0, New IntPtr(resultData.Scan0.ToInt32() + i * resultData.Stride), resultData.Stride)

            Next
        Finally
            result.UnlockBits(resultData)
            image.UnlockBits(imageData)
            mask.UnlockBits(maskData)
        End Try

        Return result
    End Function
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.