Beispiel #1
0
/*
  <img src="../test_results/TestFillStyle.png"/>
*/
func TestFillStyle() {
	i, gc := initGc(w, h)
	gc.SetLineWidth(6)

	draw2d.Rect(gc, 12, 12, 244, 70)

	wheel1 := new(draw2d.PathStorage)
	wheel1.ArcTo(64, 64, 40, 40, 0, 2*math.Pi)
	wheel2 := new(draw2d.PathStorage)
	wheel2.ArcTo(192, 64, 40, 40, 0, 2*math.Pi)

	gc.SetFillRule(draw2d.FillRuleEvenOdd)
	gc.SetFillColor(color.NRGBA{0, 0xB2, 0, 0xFF})

	gc.SetStrokeColor(image.Black)
	gc.FillStroke(wheel1, wheel2)

	draw2d.Rect(gc, 12, 140, 244, 198)
	wheel1 = new(draw2d.PathStorage)
	wheel1.ArcTo(64, 192, 40, 40, 0, 2*math.Pi)
	wheel2 = new(draw2d.PathStorage)
	wheel2.ArcTo(192, 192, 40, 40, 0, -2*math.Pi)

	gc.SetFillRule(draw2d.FillRuleWinding)
	gc.SetFillColor(color.NRGBA{0, 0, 0xE5, 0xFF})
	gc.FillStroke(wheel1, wheel2)
	saveToPngFile("TestFillStyle", i)
}
Beispiel #2
0
func android(gc draw2d.GraphicContext, x, y float64) {
	gc.SetLineCap(draw2d.RoundCap)
	gc.SetLineWidth(5)
	gc.ArcTo(x+80, y+70, 50, 50, 180*(math.Pi/180), 360*(math.Pi/180)) // head
	gc.FillStroke()
	gc.MoveTo(x+60, y+25)
	gc.LineTo(x+50, y+10)
	gc.MoveTo(x+100, y+25)
	gc.LineTo(x+110, y+10)
	gc.Stroke()
	draw2d.Circle(gc, x+60, y+45, 5) // left eye
	gc.FillStroke()
	draw2d.Circle(gc, x+100, y+45, 5) // right eye
	gc.FillStroke()
	draw2d.RoundRect(gc, x+30, y+75, x+30+100, y+75+90, 10, 10) // body
	gc.FillStroke()
	draw2d.Rect(gc, x+30, y+75, x+30+100, y+75+80)
	gc.FillStroke()
	draw2d.RoundRect(gc, x+5, y+80, x+5+20, y+80+70, 10, 10) // left arm
	gc.FillStroke()
	draw2d.RoundRect(gc, x+135, y+80, x+135+20, y+80+70, 10, 10) // right arm
	gc.FillStroke()
	draw2d.RoundRect(gc, x+50, y+150, x+50+20, y+150+50, 10, 10) // left leg
	gc.FillStroke()
	draw2d.RoundRect(gc, x+90, y+150, x+90+20, y+150+50, 10, 10) // right leg
	gc.FillStroke()
}
Beispiel #3
0
func TestBigPicture() {
	i, gc := initGc(w, h)
	gc.SetLineWidth(10)

	draw2d.Rect(gc, 0, 0, w, h)
	gc.Fill()
	saveToPngFile("TestBigPicture", i)
}
Beispiel #4
0
func windowPaintGen(x interface{}) (pf PaintFunc) {
	wf := x.(*WindowFoundation)
	return func(gc draw2d.GraphicContext) {
		gc.SetFillColor(color.White)
		draw2d.Rect(gc, 0, 0, wf.Size.X, wf.Size.Y)
		gc.Fill()
	}
	return
}
Beispiel #5
0
func (d *Display) SetHeadingText(text string) {
	d.gc.SetStrokeColor(color.White)
	d.gc.SetFillColor(color.White)
	draw2d.Rect(d.gc, d.bord, d.bord, d.bord+d.w, d.bord+d.head)
	d.gc.FillStroke()
	d.gc.SetStrokeColor(color.Black)
	d.gc.SetFillColor(color.Black)
	d.gc.FillStringAt(text, d.bord*2, d.bord+d.head-1)
}
Beispiel #6
0
func TestFillString() {
	draw2d.SetFontFolder("../resource/font/")
	i, gc := initGc(100, 100)
	draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10)
	gc.FillStroke()
	gc.SetFillColor(image.Black)
	gc.SetFontSize(18)
	gc.Translate(6, 52)
	gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold | draw2d.FontStyleItalic})
	width := gc.FillString("cou")
	gc.Translate(width+1, 0)
	left, top, right, bottom := gc.GetStringBounds("cou")
	gc.SetStrokeColor(color.NRGBA{255, 0x33, 0x33, 0x80})
	draw2d.Rect(gc, left, top, right, bottom)
	gc.SetLineWidth(3.0)
	gc.Stroke()
	gc.SetStrokeColor(image.Black)
	gc.SetLineWidth(1.0)
	gc.StrokeString("cou")
	saveToPngFile("TestFillString", i)
}
func main() {
	var url string
	var target_file string
	var AndroidApi string
	var ScreenSize string
	var Density string
	var DeviceID string
	flag.StringVar(&url, "Url", "url", "Qr code content")
	flag.StringVar(&target_file, "Output", "Target", "output file name")
	flag.StringVar(&DeviceID, "ID", "Device ID", "Device ID")
	flag.StringVar(&AndroidApi, "API", "API", "Android api level")

	flag.StringVar(&ScreenSize, "Size", "ScreenSize", "screen size")
	flag.StringVar(&Density, "Den", "Den", "Density")
	flag.Parse()
	fmt.Println("url\t:", url)
	fmt.Println("Output\t:", target_file)
	fmt.Println("ID\t:", DeviceID)
	fmt.Println("API\t:", AndroidApi)
	fmt.Println("Size\t:", ScreenSize)
	fmt.Println("Den\t:", Density)
	var q *qrcode.QRCode
	q, err := qrcode.New(url, qrcode.Highest)
	qrimg := q.Image(600)
	m := image.NewRGBA(image.Rect(0, 0, 1100, 600)) //*NRGBA (image.Image interface)
	draw.Draw(m, m.Bounds(), qrimg, image.ZP, draw.Over)
	gc := draw2d.NewGraphicContext(m)
	draw2d.Rect(gc, 580, -50, 1100, 600)
	gc.SetStrokeColor(image.Black)
	gc.SetFillColor(image.White)
	gc.FillStroke()
	gc.SetFillColor(image.Black)
	gc.SetFontSize(200)
	//gc.Translate(X, Y)
	gc.Translate(580, 250)
	//width := gc.FillString(DeviceID)
	gc.FillString(DeviceID)
	gc.Translate(30, 120)
	gc.SetFontSize(64)
	gc.FillString("API   : " + AndroidApi)
	gc.Translate(0, 80)
	gc.FillString("SIZE : " + ScreenSize)
	gc.Translate(0, 80)
	gc.FillString(Density)
	w, err := os.Create(target_file + ".jpg")
	defer w.Close()
	jpeg.Encode(w, m, nil)
	file, err := os.Open(target_file + ".jpg")
	if err != nil {
		log.Fatal(err)
	}

	// decode jpeg into image.Image
	img, err := jpeg.Decode(file)
	if err != nil {
		log.Fatal(err)
	}
	file.Close()

	// resize to width 1000 using Lanczos resampling
	// and preserve aspect ratio
	im := resize.Resize(180, 0, img, resize.Lanczos3)

	out, err := os.Create(target_file + ".jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer out.Close()

	// write new image to file
	jpeg.Encode(out, im, nil)

}