Vector graphics picture won't save

My problem is I already have a complex method (with sub-methods) that paints beautifully on a canvas. When I try to convert that set of methods into a picture, I lose the vectored text. In my method(s) I use DrawObject and DrawText with stringshapes.

So really all I want to do is save the results of my canvas paint into a picture which I can use on another window, or save. I can easily save it but only as a bitmap graphic.

When I try what you suggest – drawing into this new picture, it breaks on a Nil object … the graphics object. It’s all very confusing to me: a house of mirrors.

I miss my Commodore 64 days: 10 Print “Hello”. :rofl:

1 Like

That is correct. You can either do Vector or Bitmap. Object2D objects will work with both, but if you’re drawing into a bitmap image, they convert to bitmap. To create a vector image, you must only use Object2D. There is no Graphics or RGBSurface available. You can only use DrawObject commands, which work for both, but is the only way to create a vector image.

I see. Well tell me, is there any way I can save as a picture what I’m drawing into a canvas and keep the vectored (I guess that’s the word) text? As it is now, I can paint my original canvas, get smooth text, and output it to a PDF file. But I can’t save the whole process except as a bitmap.

I appreciate your help.

Have two pictures, one with vector content and one bitmap. Draw bitmap first then draw vector picture into the drawn bitmap?

Or just use a group2D with a PixMapShape (or whatever it is called now) for the bitmap drawing and your text as StringShapes (or whatever they are called in API 2)

-Karen

It looks a bit overwhelming at this point. I have fairly complex drawing routines (it’s for anacrostic puzzle creation which involves a lot of lines in a grid, in answer blanks, etc. as well as a lot of stringshapes in clues, indexes, etc.) I’ve used my software for 20+ years to create puzzles for our local paper. Now I want to add a feature where I could create two puzzles on one page. Thought it’d be fairly easy – and it is if I use bitmaps – but I’m starting to look for other options, maybe some third-party PDF deal that could stitch two PDFs together.

Restart your design.

  1. Create an Offscreen Picture (as Property)
    You draw everything there (instead of in Canvas.Graphics).

  2. You apply your Offscreen Picture property to the Canvas Backdrop for display:


cCanvas.Backdrop = Offscreen
  1. You print / save the Offscreen Picture.

Follow the Documentation for the details / show the offending code in case of trouble…

I’ll try this. Thanks for suggestion.

I’m still getting a Nil exception. Here’s the line of code I’m using to print to an offscreen picture (which is wDrawPuzzle):

PS.PrintPuzzle(wDrawPuzzle.Graphics)

The PS.PrintPuzzle method is what normally draws onto the canvas.

Vector images do not have a Graphics object. You must use Object2D exclusively.

1 Like

I guess we traversed this territory already. Sigh. I’m giving up on this whole concept. I don’t want to rewrite the drawing routines that go into painting on a canvas. Guess I’ll just use PDF editing software to paste together two pages (though even that appears to be a bit hard to come by).

But while I still have you on the line, Tim, why is it a canvas can handle both bitmaps and vectors? It seems anyway like it is for me. Plus I can print just fine with my present methods. I didn’t define an Object2D anywhere, I don’t think.

RoundRectShape is an Object2D. It can draw into both a bitmap and a vector image. If you create a bitmap Picture, it will have a Graphics property and will allow you to draw vector objects into it, but the result will be a bitmap, not a vector image. If you want to create a vector image that can be saved as a vector and not a bitmap, you need to create a vector Picture, but it won’t have a Graphics property - it will be Nil.

Okay, I guess I will go one more time on this. But I don’t know how to create a “vector picture” as opposed to just a picture.

Oh, just saw you wrote this above:
New Picture(200, 200, 0) creates a vector image.

I’ll try again.

Btw, I just did a search and found a thread related to this issue … a thread I started. Ay-yi-yi. I forgot I went down this whole path a couple years ago. I remember doing it now but don’t remember what my final resolution was (probably there was no resolution). At any rate, sorry to all who may think I keep banging the same drum.

I’m going to pester you one last time, Tim. Can you show me – since I can’t find an example in the docs anywhere – how to create a vector picture and draw a single object into it.

Consider this approach:

Ignore the ‘vector picture’ for now.

Start with a Group2D object.
Add vector items to that, such as stringshapes and figureshapes

Test that it works by having a canvas on screen, and in the paint event of the canvas, do

g.drawobject MyGroup2d, 100,100

(if you see the graphics, your Group is fine.)

Now, create a new picture with 0 depth

Mypic = newpicture (1000,1000,0)

Set the Objects property of that to be your group.
Save the picture.

(The Objects property can be considered a Group2D in it’s own right… you can add your vector shapes directly to that if you like, you can omit the canvas step when you are happy)

Well, there a re a lot of bad misconceptions in this thread:

  1. First of all, Xojo kind of sucks with vector support.

  2. You only can save “vector graphics” in EMF files (Yes the cuting edge technology from Windows NT 3.1)

  3. “I can’t find an example in the docs anywhere”, someone already post the link to the documentation where is the explanation and such example: Drawing with Vector Graphics — Xojo documentation

The answer:

Well, your question has being already asnwered many times, just read the documentation: Drawing with Vector Graphics — Xojo documentation

  1. Draw everyting to a temp picture
  2. Draw using only Object2D
  3. Save with Picture.SaveAsDefaultVector
  4. And paint that picture to the canvas.

NO, YOU CANT SAVE VECTOR GRAPHICS…

  • while mixing bitmap drawing
  • drawing in the paint event of a canvas
  • without refactoring your drawing code

Alternative:

Instead of looking for vector drawing, you can refactor your drawing code to accept parameters for width and heigh so you can draw the bitmap with the size needed.

I did read the docs. Several times. Here’s some code directly copied from the docs which you referenced:

Var r As New RoundRectShape
r.Width = 120
r.Height = 120
r.Border = 100
r.BorderColor = Color.RGB(0, 0, 0) // black
r.FillColor = Color.RGB(255, 102, 102)
r.CornerHeight = 15
r.CornerWidth = 15
r.BorderWidth = 2.5

SavePicture.Graphics.DrawObject(r, 100, 100)

The SavePicture is a window property. And you know what happens? Nil. Nil nil nil. Maybe you should scold me again. Maybe then I’d get another Nil.

I copied the code and it saves the emf file as intended…

image

Are you initializing the SavePicture object? :roll_eyes:
(Tim is wrong you have to initialize it withouth the third parameter for saving it as vector)

SavePicture = New Picture(200, 200)

But as already said, xojo sucks with vector graphics, it is better to just draw a bitmap of the exact size you need it.

2 Likes