#๐Ÿ”’ setbitmapbits is not an ATTRIBUTE????

102 messages ยท Page 1 of 1 (latest)

clear snowBOT
#

@modern kelp

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

modern kelp
#

Traceback (most recent call last):
File "C:\Users****\Desktop\visual glitch\COOL.py", line 95, in <module>
screenshot.SetBitmapBits(hue_shifted_array.tobytes())
AttributeError: 'PyCBitmap' object has no attribute 'SetBitmapBits'

latent viper
#

and? what is PyCBitmap?

#

or are we supposed to know that

modern kelp
#

idk i dont know as well i just saw this in a tutorial that got nearly no views

latent viper
#

maybe not a great tutorial?

modern kelp
#

ye but how do i do it then cuz i gotta edit the memory by Extracting which i can do

#

but

#

i cant put it back into the mem_smth

latent viper
#

have you checked what methods it does have then?

modern kelp
#

yes

latent viper
#

and?

modern kelp
faint plank
#

The error is clear, the object doesn't have such setter.
And why do you want to set it? You don't use that screenshot variable anywhere after, you do blt later with something else

latent viper
#

no, but using dir()

#

what your IDE says is irrelevant

modern kelp
#

wdym

latent viper
#

they often get these things wrong

modern kelp
#

so how can i fix it

#

cuz i need a way to retrieve and set data manually unlike mem_dc.BitBlt((0, 0), (width, height), dc, (0, 0), win32con.SRCCOPY)

faint plank
# modern kelp wdym

Those hints in IDE guessed from type hints, they are not always reflecting the truth

latent viper
#

well maybe first use dir() to check what methods it does actually have

#

like I suggested earlier

modern kelp
#

how do i do that

latent viper
#

that function returns a list of attributes the object has

modern kelp
#

so screenshot.dir()

latent viper
#

no, dir(screenshot) and do something with the return value

modern kelp
#

ok

#

['AttachObject', 'CreateCompatibleBitmap', 'GetAttachedObject', 'GetBitmapBits', 'GetHandle', 'GetInfo', 'GetSize', 'LoadBitmap', 'LoadBitmapFile', 'LoadPPMFile', 'Paint', 'SaveBitmapFile', 'class', 'delattr', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook']

#

Btw this is the firs time i have used win32 so idk anything basically

latent viper
#

I haven't used it either, but looks like the method you're looking to use doesn't exist there

modern kelp
#

so do i just not set the bitmapbits and just select the object? but then i havent saved the changes onto the screenshot

#

so it wont get applied

latent viper
#

if you want to alter the screenshot, maybe use Pillow for that

modern kelp
#

ill try

#

no

#

it doesnt work

latent viper
#

"doesn't work"?

modern kelp
#

pillow has no way to "directly" alter the data, it has to retrieve, alter then change the value to the altered value

#

but then win32 has given no way to change the value

latent viper
#

what alterations are you looking to make then?

modern kelp
#

i wanna change the hue

#

but unlike the tearing effect

latent viper
#

so import it to Pillow and then use its API to make the changes?

modern kelp
#

yes thats what im trying to do but then when i try to put it back Onto the screenshot so that i can send it into the mem_dc, it doesnt work cuz theres no way to put it back onto the screenshot

latent viper
#

what's that supposed to do then

#

you take a screenshot, then alter its hue, then what?

modern kelp
#

you take a screenshot, make a duplicate that pillow can use, and then try to replace the original screenshot with the duplicate

#

but i cant do the last step

#

this code gets the screenshot and immediately puts it into the memory but i dont know how to turn it into the screenshot like this does
mem_dc.BitBlt((0, 0), (width, height), dc, (0, 0), win32con.SRCCOPY)

latent viper
#

"replace the original" - this part I don't understand

#

what is the practical thing you want to achieve after altering the hue?

modern kelp
#

value1 = 1
value1copy = value1
value1copy += 1 <----- changing the hue
value1 = value1copy

latent viper
#

this doesn't tell me anything

modern kelp
#

im trying to make a copy and then reassigning screenshot to be the copy

latent viper
#

huh?

#

and do what with the screenshot then?

modern kelp
#

pillow cant do effects on the screenshot so i need to make a copy, turn it into the format that pillow can use

latent viper
#

can you please just answer my simple question

modern kelp
#

afterwards i take the screenshot and make the tearing effect and put it on screen

#
if random.choice([True, False]):
            x_start = random.randint(0, width - 1)
            x_end = random.randint(x_start, width)
            y_offset = random.randint(-40, 40)

            dc.BitBlt(
                (x_start, y_offset),
                (x_end - x_start, height - abs(y_offset)),
                mem_dc,
                (x_start, 0),
                win32con.SRCCOPY
            )
        else:
            y_start = random.randint(0, height - 1)
            y_end = random.randint(y_start, height)
            x_offset = random.randint(-40, 40)

            dc.BitBlt(
                (x_offset, y_start),
                (width - abs(x_offset), y_end - y_start),
                mem_dc,
                (0, y_start),
                win32con.SRCCOPY
            )```
latent viper
#

ok, so "displaying the altered screenshot" was the answer

#

and can that not be done with Pillow?

modern kelp
#

yes but i dont know how format back into the way that win32 can display it

latent viper
#

meaning you can't figure out how to make Pillow display images on the screen?

modern kelp
#

no i want pillow to alter, then Somehow change it back into the format that win32 can use so that win32 displays it directly instead of pillow showing on like a window

latent viper
#

by directly you mean in full screen?

#

would a borderless screen-sized window not work?

modern kelp
#

no because you cannot interact with the rest of the operating system such as other apps

latent viper
#

...huh?

#

I'm totally not getting what you want

modern kelp
#

i want it so that it like goes rainbow on the screen while you can use other apps

#

like a filter on screen

latent viper
#

oh

#

is that even possible?

modern kelp
#

yes cuz if i only do the tearing effect, it works, i can also draw on screen, that works

#

but i cant make a hue changeeffect

latent viper
#

then IDK

faint plank
modern kelp
#

wdym@faint plank

#

you mean the tearing effect

#

and the line effect

#

OHHH I used dc

#

using dc i captured the screen and put it into mem_dc i think

#

I capture using dc and then put it into mem_dc, then i display the stuff in mem_dc by sending it back to dc using BitBlt

#

for the draw theres a draw attribure for dc

faint plank
#

Yep. Dc seems to be something related to display, screenshot is just a c bitmap.

As I said previously, in the current code you didn't even plan how to use the screenshot after writing to it - there's some blt later, but it didn't use the screenshot variable. That's what clued me in that you maybe don't need to change screenshot var, just blt whatever you need

modern kelp
#

i just display it at different positions

#

using dc

faint plank
#

You don't use the screenshot variable in the if/else part.

modern kelp
#

so how to fix

faint plank
#

Use the bit blt thing to write mem_dc directly to dc, just like you did with the tearing.

Instead of trying to write mem_dc to the screenshot variable

modern kelp
#

but how do i use pillow then because its not in a format that pillow can use

faint plank
#

I don't mean to get rid of the whole screenshot variable, just the part where you try to write to it (the SetBitmapBits part)

Instead we just need to find how to write numpy array (the type of your hue_shifted_array) to dc
That means we gotta convert numpy array to a type it can accept

modern kelp
#

It only accepts the bitmap variable(screenshot) that Win32 makes I think

#

If I also don't write to the screenshot variable, then why should we have it

#

@faint plank

clear snowBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.