-1

I used code by this question and this is what I have:

from io import BytesIO
import win32clipboard
from PIL import Image

image = Image.open('image.jpg')
output = BytesIO()
image.convert('RGB').save(output, 'BMP')
data = output.getvalue()[14:]
output.close()

win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
win32clipboard.CloseClipboard()

now what should I do if I wanna copy the word 'hello' before the image go down one line and then the image

I tried doing this

win32clipboard.SetClipboardData(win32clipboard.CF_DIB,BytesIO(StringIO('hello_world' + '\n').read().encode('utf8')) + data)

but it gave me: TypeError: unsupported operand type(s) for +: '_io.BytesIO' and 'bytes'

ZombZ
  • 3
  • 1
  • win32clipboard.SetClipboardData(win32clipboard.CF_DIB,BytesIO(StringIO(f'hello_world "\n" {data}').read().encode('utf8')) – toyota Supra Apr 27 '23 at 01:22

1 Answers1

0

Get the bytes from the BytesIO

BytesIO(StringIO('hello_world' + '\n').read().encode('utf8')).getvalue() + data

But really it's just either of the following

'hello_world\n'.encode('utf8') + data
b'hello_world\n' + data
azro
  • 53,056
  • 7
  • 34
  • 70
  • when I try and paste it it just shows me the picture can't be displayed – ZombZ Apr 26 '23 at 19:33
  • @ZombZ how can you expect the image viewer to display a wrong file image ? You have broken it by putting bytes that shouldn't be here – azro Apr 30 '23 at 10:47