Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3804

Save picture from PDF: UnsupportedOperationException

$
0
0

I try to use the following code, from documentation page: Picture — Xojo documentation

Var imageData As String
Var bs As BinaryStream
Var f As FolderItem
If ImageWell1.Image <> Nil Then
  ' Get a temporary file to save the image to
  If Picture.IsExportFormatSupported(Picture.Formats.JPEG) Then
    f = SpecialFolder.Temporary.Child("TempImage.jpg")

    ' Save the image out to the file
    ImageWell1.Image.Save(f, Picture.Formats.JPEG)
  End If

  ' Open the file as a BinaryStream and read the data in
  bs = BinaryStream.Open(f, False)
  If bs <> Nil Then
    imageData = bs.Read(bs.Length)
    bs.Close
  End If

  ' delete the temporary file if it exists
  If f.Exists Then
    f.Delete
  End If
End If

I need to adapt this code, my image comes from a pdf file. When I execute this code I have an exception on the save line:

UnsupportedOperationException Error: Saving a multi-representation Picture is not supported

Var p As Picture
Var tmp As FolderItem
p = Picture.Open(file)

ImageViewer1.Image = p

If Picture.IsExportFormatSupported(Picture.Formats.JPEG) Then
  tmp = SpecialFolder.Temporary.Child("TempImage.jpg")
  'tmp = SpecialFolder.Desktop.Child("TEST.jpg")
  
  ' Save the image out to the file
  Try
    p.Save(tmp, Picture.Formats.JPEG)
    
  Catch error As UnsupportedOperationException
    MessageBox("UnsupportedOperationException Error: " + error.Message)
  End Try
End If

Any idea?

7 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 3804

Trending Articles