Skip to content

Commit 2c647e0

Browse files
committed
fix export_to_png with img_sdl2
1 parent b81d873 commit 2c647e0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

kivy/core/image/_img_sdl2.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ def init():
2323

2424
_is_init = 1
2525

26-
2726
def save(filename, w, h, fmt, pixels, flipped):
2827
# this only saves in png for now.
2928
cdef bytes c_filename = filename.encode('utf-8')
3029
cdef int pitch
3130
pitch = w * 4
3231

33-
cdef SDL_Surface *image = SDL_CreateRGBSurfaceFrom(<void *>pixels, w, h, 32, pitch, 0x00000000ff, 0x0000ff00, 0x00ff0000, 0xff000000)
32+
if flipped:
33+
Logger.warn(
34+
'ImageSDL2: saving flipped textures not supported; image will be flipped')
35+
cdef SDL_Surface *image = SDL_CreateRGBSurfaceFrom(<void *>pixels + 36, w, h, 32, pitch, 0x00000000ff, 0x0000ff00, 0x00ff0000, 0xff000000)
3436

3537
IMG_SavePNG(image, c_filename)
3638
SDL_FreeSurface(image)

kivy/uix/widget.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def on_touch_down(self, touch, after=False):
172172
from kivy.properties import (NumericProperty, StringProperty, AliasProperty,
173173
ReferenceListProperty, ObjectProperty,
174174
ListProperty, DictProperty, BooleanProperty)
175-
from kivy.graphics import Canvas, Translate, Fbo, ClearColor, ClearBuffers
175+
from kivy.graphics import Canvas, Translate, Fbo, ClearColor, ClearBuffers, Scale
176176
from kivy.base import EventLoop
177177
from kivy.lang import Builder
178178
from kivy.context import get_current_context
@@ -555,11 +555,12 @@ def export_to_png(self, filename, *args):
555555
with fbo:
556556
ClearColor(0, 0, 0, 1)
557557
ClearBuffers()
558-
Translate(-self.x, -self.y, 0)
558+
Scale(1, -1, 1)
559+
Translate(-self.x, -self.y - self.height, 0)
559560

560561
fbo.add(self.canvas)
561562
fbo.draw()
562-
fbo.texture.save(filename)
563+
fbo.texture.save(filename, flipped=False)
563564
fbo.remove(self.canvas)
564565

565566
if self.parent is not None:

0 commit comments

Comments
 (0)