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

Notification

Icon
Error

Options
Go to last post Go to first unread
irwan  
#1 Posted : Monday, May 22, 2006 12:27:48 PM(UTC)
irwan

Rank: Member

Groups: Member
Joined: 2/16/2006(UTC)
Posts: 7

Hi, I am working on a transparent gif, but after I rotate it and stored the image into a control it becomes not transparent anymore can you please help
Code:
BView.BITMAP.IsLzwEnabled = True
        BView.BITMAP.LoadFromFile (a.gif)
        BView.BITMAP.Data.ConvertTo32bppArgb
        pWidth = Screen.TwipsPerPixelX * ImageWidth / PlanScale
        pHeight = CInt(pWidth * BView.BITMAP.Data.Height / BView.BITMAP.Data.Width)
        BView.BITMAP.ApplyInPlace = True
        BView.BITMAP.Transforms.Resize , CInt(pHeight / Screen.TwipsPerPixelX), InterpolationModeHighQuality
        BView.BITMAP.Transforms.Rotate Rotation, InterpolationModeHighQuality
        BView.BITMAP.Channels.Transparentize ColorRed, 20
        BView.BITMAP.FormatAutoSelect = False
        BView.BITMAP.Formats.SelectCurrent ("GIF")
        BView.BITMAP.Formats.GifIsTransparent = True
        With fNode
            Set .Picture = BView.BITMAP.Data.Picture

Edited by user Wednesday, December 19, 2007 4:34:08 PM(UTC)  | Reason: Not specified

Andrew  
#2 Posted : Tuesday, May 23, 2006 12:41:38 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 866

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
Hi, First of all, Picture does not support alpha channel transparency. It supports only transparent color in palettes. So if you need to have transparency in Picture control, you need to convert the bitmap to 8-bit indexed pixel format and set appropriate transparent color in it. Bad news is that Graphics Mill is not able to transmit the transparent color to the Picture object. The only way to do it is to save the image to a temporary file and load it to the Picture. Something like this:
Code:
BView.Bitmap.IsLzwEnabled = True
BView.Bitmap.LoadFromFile ("C:\[Test Files]\t.gif")
BView.Bitmap.Data.ConvertTo32bppArgb
pWidth = Screen.TwipsPerPixelX * ImageWidth / PlanScale
pHeight = CInt(pWidth * BView.Bitmap.Data.Height / BView.Bitmap.Data.Width)

BView.Bitmap.ApplyInPlace = True
BView.Bitmap.Transforms.Resize , CInt(pHeight / Screen.TwipsPerPixelX), InterpolationModeHighQuality
BView.Bitmap.Transforms.Rotate Rotation, InterpolationModeHighQuality

BView.Bitmap.Data.ConvertTo8bppIndexed DitheringTypeNone
BView.Bitmap.Data.Palette.SetTransparentColor ColorRed

BView.Bitmap.FormatAutoSelect = False
BView.Bitmap.Formats.SelectCurrent ("GIF")
BView.Bitmap.Formats.GifIsTransparent = True

BView.Bitmap.SaveToFile "c:\temp\temp.gif"
Picture1.Picture = LoadPicture("c:\temp\temp.gif")
But could you explain why it is necessary to use Picture object to display a bitmap instead of BitmapViewer?

Edited by user Wednesday, December 19, 2007 4:34:33 PM(UTC)  | Reason: Not specified

irwan  
#3 Posted : Sunday, May 28, 2006 4:02:54 PM(UTC)
irwan

Rank: Member

Groups: Member
Joined: 2/16/2006(UTC)
Posts: 7

Hi Andrew, Thank you for the reply, the reason I would need to put it back to the picture properties is because I use it for different components. Is it possible to do savetomemory as savetofile can be quite time consuming Regards, Irwan
Andrew  
#4 Posted : Monday, May 29, 2006 2:41:40 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 866

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
If you know how to load Picture object from array (rather than from file), you can use SaveToMemory. Also, if the second component you retrieve an image to supports direct access to memory and possibility to modify palette transparency, you could copy pixels and palette manually instead of using intermediary Picture object.
irwan  
#5 Posted : Tuesday, May 30, 2006 1:14:55 AM(UTC)
irwan

Rank: Member

Groups: Member
Joined: 2/16/2006(UTC)
Posts: 7

Hi Andrew, Would you be able to give me an example on how to load from memory to a picture box. Thank you Best regards, Irwan
Andrew  
#6 Posted : Wednesday, May 31, 2006 10:26:43 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 866

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
There is no standard way, however you can do it using WinAPI. For example, here you can find a function which loads Picture object from byte array: http://www.xtremevbtalk.com/printthread.php?t=129873 Here posted the LoadPictureFromByteArray function:
Code:
   ' Imports from WinAPI
    Private Declare Sub OleLoadPicture Lib "olepro32" (ByVal Stream As stdole.IUnknown, ByVal Size As Long, ByVal RunMode As Long, riid As UUID, ipic As StdPicture)
    Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal HGlobal As Long, ByVal DeleteOnRelease As Long, IStreamPtr As stdole.IUnknown) As Long
    Private Type UUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(0 To 7) As Byte
    End Type

    ' Implementation of the function
    Function LoadPictureFromByteArray(Bytes() As Byte) As StdPicture
        Dim Stream As stdole.IUnknown
        CreateStreamOnHGlobal VarPtr(Bytes(LBound(Bytes))), 0, Stream
        Dim IPictureUUID As UUID
        With IPictureUUID
            .Data1 = &H7BF80980
            .Data2 = &HBF32
            .Data3 = &H101A
            .Data4(0) = &H8B
            .Data4(1) = &HBB
            .Data4(2) = &H0
            .Data4(3) = &HAA
            .Data4(4) = &H0
            .Data4(5) = &H30
            .Data4(6) = &HC
            .Data4(7) = &HAB
        End With
        
        Dim Pic As StdPicture
        OleLoadPicture Stream, 0, 1, IPictureUUID, LoadPictureFromByteArray
    End Function
It is used very simple: just call Bitmap.SaveToMemory and pass the result into this function:
Code:
Picture1.Picture = LoadPictureFromByteArray(BView.Bitmap.SaveToMemory)
Hope this helps.

Edited by user Wednesday, December 19, 2007 4:34:45 PM(UTC)  | Reason: Not specified

Users browsing this topic
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.