OVH Cloud OVH Cloud

Sauvegarder un BITMAP dans un fichier

4 réponses
Avatar
Jean Christophe Avard
Là tabarnack je suis à près perdre patience calise. J'ai un objet bitmap que
je dois sauvegarder dans un fichier du même type. pour ensuite l'encrypter
dans une librairie protégé. Là le problème est que je dois sauvegarder le
bitmap en fichier et hje suis pas capable, j'utilise la fonction SAVE de
BITMAP mais christ ca marche pâs, et pourtant je fourni le bon argument, SVP
je suis a bout là!

4 réponses

Avatar
Christian Hugoud
Mets un bout du code que nous puissions t'aider.

Christian

"Jean Christophe Avard" a écrit dans le message de news:

Là tabarnack je suis à près perdre patience calise. J'ai un objet bitmap
que je dois sauvegarder dans un fichier du même type. pour ensuite
l'encrypter dans une librairie protégé. Là le problème est que je dois
sauvegarder le bitmap en fichier et hje suis pas capable, j'utilise la
fonction SAVE de BITMAP mais christ ca marche pâs, et pourtant je fourni
le bon argument, SVP je suis a bout là!



Avatar
Jean Christophe Avard
Ça c'est le code que j'ai lorsque je drop un fichier dans mon application

Private Sub ListView1_DragDrop(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop

Dim cnn As New OleDbConnection(CONST_CONNECTION_STRING)

Dim cmm As New OleDbCommand

Dim newms As MemoryStream

Dim img As Image

Dim sFile() As String

Dim itm As New ListViewItem

Dim index As Integer = ImageList2.Images.Count

Dim i, id As Integer

Dim sLib, sFilename As String

Try

If e.Data.GetDataPresent(DataFormats.FileDrop) Then ' Image File being
dropped

sFile = e.Data.GetData(DataFormats.FileDrop)

pBar.Visible = True

pBar.Minimum = 1

pBar.Maximum = sFile.Length

pBar.Value = 1

pBar.Step = 1

For i = 0 To sFile.Length - 1

' vérifie s'il s'agit d'une fichier d'image

Dim ImgTest As Image = Image.FromFile(sFile(i))

ImgTest = Nothing

' appele la function qui ajoute l'image

addImage(sFile(i))

pBar.PerformStep()

Application.DoEvents()

Next

ElseIf e.Data.GetDataPresent(DataFormats.Dib) Then ' Image dragged from
Corel Designer

HandleDropOrPaste(e.Data)

MsgBox(Application.StartupPath & "fuckitallostiedechrist")

'_bmp.Save(Application.StartupPath & "fuckitallostiedechrist.txt",
Imaging.ImageFormat.Png)

itm.ImageIndex = ImageList2.Images.Count

ImageList2.Images.Add(_bmp)

ListView1.Items.Add(itm)



End If

Catch ex As Exception

MessageBox.Show(MSGBOX_ERROR_INVALID_TYPE + sFile(i), MSGBOX_ERROR,
MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)

'MsgBox(ex.ToString)

Finally

pBar.Visible = False

End Try


----------------------

Ca c'est le code que j'utilise pour convertir le Dib en BITMAP (ca vient de
MSDN)

Module Drag

Private Const BMFSIZE As Integer = 14

Private Const BMIHSIZE As Integer = 40

Public _bmp As Bitmap

<StructLayout(LayoutKind.Explicit, CharSet:=CharSet.Unicode)> _

Class BITMAPFILEHEADER

<FieldOffset(0)> Public bfType As UInt16

<FieldOffset(2)> Public bfSize As UInt32

<FieldOffset(6)> Public bfReserved1 As UInt16

<FieldOffset(8)> Public bfReserved2 As UInt16

<FieldOffset(10)> Public bfOffBits As UInt32

End Class

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _

Class BITMAPINFOHEADER

Public biSize As Int32

Public biWidth As Int32

Public biHeight As Int32

Public biPlanes As Int16

Public biBitCount As Int16

Public biCompression As Int32

Public biSizeImage As Int32

Public biXPelsPerMeter As Int32

Public biYPelsPerMeter As Int32

Public biClrUsed As Int32

Public biClrImportant As Int32

End Class

Public Sub HandleDropOrPaste(ByRef data As DataObject)

' --- CF_BITMAP test ---

' This line uses the CF_BITMAP data to create a bitmap object directly...

' _bmp = data.GetData(DataFormats.Bitmap)



' --- CF_DIB test ---

' From here we need to create a Bitmap object from the MemoryStream that
contains the CF_DIB data

' But we also need to prepend the data with a BITMAPFILEHEADER

' This pulls the bitmap data from the clipboard. It does not contain a
BITMAPFILEHEADER...

Dim stm As MemoryStream = data.GetData(DataFormats.Dib)

If stm Is Nothing Then

Return

End If

' Read the data from the stream above into a Byte array...

Dim bytes(stm.Length) As Byte

Dim i As Integer

i = stm.Read(bytes, 0, stm.Length)

stm.Close()

If i = 0 Then

Return

End If

' Setup a BITMAPFILEHEADER which we need before the clipboard data...

Dim bmf As New BITMAPFILEHEADER

bmf.bfType = UInt16.Parse(&H4D42)

bmf.bfSize = UInt32.Parse(BMFSIZE + i)

bmf.bfReserved1 = UInt16.Parse(0)

bmf.bfReserved2 = UInt16.Parse(0)

bmf.bfOffBits = UInt32.Parse(BMFSIZE + BMIHSIZE)

' Create a new stream (newstm) which we will fill with all the data we
need...

Dim newstm As New MemoryStream(BMFSIZE + i)

If newstm Is Nothing Then

Return

End If

' Put the BITMAPFILEHEADER (which we initialized above) into newstm...

Dim bmfPtr As New IntPtr

bmfPtr = Marshal.AllocHGlobal(BMFSIZE)

Marshal.StructureToPtr(bmf, bmfPtr, True)

Dim bmfBytes(BMFSIZE) As Byte

Marshal.Copy(bmfPtr, bmfBytes, 0, BMFSIZE)

newstm.Write(bmfBytes, 0, BMFSIZE)

Marshal.FreeHGlobal(bmfPtr)

' Put the data we copied from the clipboard into newstm following
BITMAPFILEHEADER...

newstm.Write(bytes, 0, i)

' Finally, create a new bitmap using the assembled stream...

If newstm.Length > 0 Then

_bmp = New Bitmap(newstm)

End If



' Cleanup and force a redraw...

newstm.Close()

'Me.Invalidate()

End Sub

End Module



"Christian Hugoud" wrote in message
news:
Mets un bout du code que nous puissions t'aider.

Christian

"Jean Christophe Avard" a écrit dans le message de news:

Là tabarnack je suis à près perdre patience calise. J'ai un objet bitmap
que je dois sauvegarder dans un fichier du même type. pour ensuite
l'encrypter dans une librairie protégé. Là le problème est que je dois
sauvegarder le bitmap en fichier et hje suis pas capable, j'utilise la
fonction SAVE de BITMAP mais christ ca marche pâs, et pourtant je fourni
le bon argument, SVP je suis a bout là!







Avatar
Jacques93
Bonjour Jean Christophe Avard,
Jean Christophe Avard a écrit :
Là tabarnack je suis à près perdre patience calise. J'ai un objet bitmap que
je dois sauvegarder dans un fichier du même type. pour ensuite l'encrypter
dans une librairie protégé. Là le problème est que je dois sauvegarder le
bitmap en fichier et hje suis pas capable, j'utilise la fonction SAVE de
BITMAP mais christ ca marche pâs, et pourtant je fourni le bon argument, SVP
je suis a bout là!





Tabarnack, t'es pas sur le bon forum là, va plutôt voir sur :

microsoft.public.fr.dotnet.vb

--
Cordialement,

Jacques.
Avatar
Jean Christophe Avard
hahah merci, j'étais faché ...
"Jacques93" wrote in message
news:O8c%
Bonjour Jean Christophe Avard,
Jean Christophe Avard a écrit :
Là tabarnack je suis à près perdre patience calise. J'ai un objet bitmap
que je dois sauvegarder dans un fichier du même type. pour ensuite
l'encrypter dans une librairie protégé. Là le problème est que je dois
sauvegarder le bitmap en fichier et hje suis pas capable, j'utilise la
fonction SAVE de BITMAP mais christ ca marche pâs, et pourtant je fourni
le bon argument, SVP je suis a bout là!



Tabarnack, t'es pas sur le bon forum là, va plutôt voir sur :

microsoft.public.fr.dotnet.vb

--
Cordialement,

Jacques.