PDA

View Full Version : RB : Save canvas to jpeg


Baldock
2002.08.01, 07:27 AM
g'day

A quick question. I'm trying to save a canvas image as a jpeg. Here is the basics of what I'm doing. I'll be honest and I can't figure out what to do. I've used google to scan the comp.lang.basic.realbasic news group and come up nothing.

sub DrawSave()
dim f as folderitem

// TopicPicture is a canvas
TopicPicture.PenHeight = 1
TopicPicture.PenWidth = 1
TopicPicture.ForeColor = RGB(0,0,0)
TopicPicture.DrawRect 0,0,WhatSize-1,WhatSize-1

f = getsavefolderitem("image/jpeg","New Topic")
if f <> Nil then
f.SaveAsJPEG TopicPicture // This generates a type mismatch but I dont know what to put in there
end if

end sub

namoreh
2002.08.01, 01:08 PM
SaveAsJPEG needs a picture, but you're giving it a Canvas, a Canvas is not a picture, just an object which can display them I would do it this way:

Dim pic As Picture

pic.PenHeight = 1
pic.PenWidth = 1
pic.ForeColor = RGB(0,0,0)
pic.DrawRect 0,0,WhatSize-1,WhatSize-1

TopicPicture.backdrop = pic //show pic in TopicPicture

f = getsavefolderitem("image/jpeg","New Topic")
if f <> Nil then
f.SaveAsJPEG pic // save the pic
end if



-Namoreh

Baldock
2002.08.01, 08:27 PM
Thanks for the hint, I had a problem for a few minutes since I was getting errors.
Had to find out that pen and draw commands have to go to the graphics part so it became

Dim pic As Picture

pic.graphics.PenHeight = 1
pic.graphics.PenWidth = 1
pic.graphics.ForeColor = RGB(0,0,0)
pic.graphics.DrawRect 0,0,WhatSize-1,WhatSize-1

TopicPicture.backdrop = pic //show pic in TopicPicture

f = getsavefolderitem("image/jpeg","New Topic")
if f <> Nil then
f.SaveAsJPEG pic // save the pic
end if

Now it works :) Thanks

Originally posted by Namoreh
SaveAsJPEG needs a picture, but you're giving it a Canvas, a Canvas is not a picture, just an object which can display them I would do it this way:

Dim pic As Picture

pic.PenHeight = 1
pic.PenWidth = 1
pic.ForeColor = RGB(0,0,0)
pic.DrawRect 0,0,WhatSize-1,WhatSize-1

TopicPicture.backdrop = pic //show pic in TopicPicture

f = getsavefolderitem("image/jpeg","New Topic")
if f <> Nil then
f.SaveAsJPEG pic // save the pic
end if

-Namoreh

namoreh
2002.08.01, 08:46 PM
i thought graphics should have been there, but i omitted it because it wasn't in your code and the only error in your code you mentioned was at the SaveAsJPEG line. glad i could help.


-Namoreh