Changing WMF color - delphi

i have been trying to change colors on a wmf canvas in Delphi, with usual images i just run a scanline or by running a loop on each X and Y pixel and give it a new color code, but with MetaCanvas this method doesnt work, maybe because it is not actually an image but instead a list of GDI functions. I read somewhere that i would need to decompile and recompile the metafile for changing color properties in it. But i dont have a clue how i will do it or if there is another easy way for it.
If anyone can point me in the right direction.
Thanks

There is a mechanism for you to modify the contents of a meta file.
Call EnumEnhMetaFile passing a callback function, EnhMetaFileProc. The callback function is called for each record in the metafile. You can take a copy of this record, modify it, and then pass it to PlayEnhMetaFileRecord.
So, you could look for records that specified colours, and make whatever modifications you need.

Related

PyPDF2: can it update data stream?

I need to get a polygon comment into a pdf and revise it's shape. I'm able to do so now by merging the pdf and a blank pdf with just the polygon, then I am able to update the vertices and the rect.
However, the polygon shape still looks the old one when opening the new pdf, even though it will be refreshed after a few clicks on the shape. I need to have this fixed and found this is probably caused by the data stream in the annotation object, which seems to still contain the old polygon shape. But I cannot figure out how to overwrite that before saving the new pdf. I used code similar below to update the vertices and rect, but cannot figure out how to update the data stream.
annot.getObject().update({NameObject('/Rect'):ArrayObject([FloatObject(min(xcoords)), FloatObject(min(ycoords)), FloatObject(max(xcoords)), FloatObject(max(ycoords))])})
Please see image in link
I would appreciate any information.
In case someone has a similar problem, just wanted to share my solution --
I don't find a way to update the stream data, however, I am able to get rid of the "ghost" shape by completely removing that object within the annotation object.
annot.getObject().pop('/AP')
Without that ghost shape, the annotation polygon displays properly! Not sure why the use of '/AP' object though. But it looks alright.

How to stroke the same layer across multiple layers

In gimp, I have about 98 layers. I have a path that I would like to stroke on across all the layers. Is there a way to do this without individually going through each layer?
You can do that easily using the Python console. I have a couple answers around with longer or shorter hints on how to use it -this is one: https://superuser.com/questions/1067478/how-to-change-several-images-in-gimp-that-are-already-open/1067867?noredirect=1
In this case, after having made a call to gimp.image_list() and selecting your target image in that list, assigning it to a image variable, just do a call to pdb.gimp_edit_stroke_vectors(...) for each layer on the images.
Therefore, your whole filters->Python-fu->Console sessions might be something along:
image = gimp.image_list()[0]
for layer in image.layers:
pdb.gimp_edit_stroke_vectors(layer, image.vectors[0])
(if your image is the last one openned (then its position on the image_list will be '0' ) and if your path is the topmost one on the paths dialog (which also will have '0' as an index).
You can use calls to pdb.gimp_context_set_foreground (or ...set_brush, and ...set_dynamics, ..set_brush_size) inside the for loop to change the respective settings as you progress through the layers, although there is no call to change the active tool. Use the "browse" button on the bottom of the Python console dialog to learn about all possible calls.

How to work with non-visible TImage32

I try to make use of a TImage32 to combine several layers with positions and transparency etc. So I create in runtime a TImage32, set parent to nil, load from file a bitmap and load from file a layer on top of that bitmap. Now I want to save the result, but I seem to be unable to find where the actual result is. If I do the same with creating the TImage32 in designtime, make it visible, the result of the combined bitmaps is in the Buffer field of TImage32, and I can save the result using Image32.Buffer.SaveToFile('test.bmp'). If the component is not visible, the Buffer is an empty bitmap and the combined bitmap seem to be not created.
Can someone shed light on this? How do I combine bitmaps with GR32, save them, but with invisible components?
Thanks a lot!
Willem
You don't need to use visual controls like TImage.
The library you're using graphics32 has all the methods you need.
Use TBitmap32: The Bitmap can be displayed and scaled using its DrawMode, MasterAlpha and StretchFilter properties.
You simply use the MyBitmap.LoadFromFile method to get it.
I suggest you then store your bitmaps in a TObjectList.
Combine them using TBitmap32.Draw{To}, note that you can use the DrawMode to modify the behavior of Draw.
And use the SaveToFile method as usual when done manipulating the bitmap.

Change the background from transparent to some color using gimp

I've large set of images. I wan't to chage their background to specific color. Lets say green. All of the images have transparent background. Is there a way to perform this action using python-fu scripting in Gimp. Or some other tool available to do this specific task in automated fashion.
Yes there is -
Although this question is not an exact duplicate, i is not practical to just type in the basics of creating a Python plug-in every time someone asks to automate some task in the GIMP
I will have to ask you to look at GIMP: Create image stack from all image files in folder and maybe some other python-fu related answers for the basics.
After you get a simple "hello world" script going, simply
register a script that asks for
a string with the desired folder, use Python's os.listdir, or glob.glob to fetch the paths
to the iamge files, and simply loop through them repeating calls to:
image = pdb.gimp_file_load (...)
image.new_layer(pos=1, fill_mode = FOREGROUND_FILL)
pdb.gimp_file_save(...)
pdb.gimp_image_delete(image)
The parameters to the PDB calls are easy to check at GIMP's help procedure browser -
the image's new_layermethod is not really documented, and can replace 3-4 pdb calls - the possible parameters to it are: "name", "width", "height", "offset_x", "offset_y",
"alpha", "pos", "opacity", "mode", "fill_mode",
all of which are optional. "pos" is the layer position: 0 is at the top of the image. "1" would be just bellow the topmost layer.
It should be clear that the gimp_image_delete call will just remove the image from memory - not the file from disk. Simply de-referencing it on the Python side won't make GIMP forget it. Likewise, if you want to interact with any image open in this way, you have to call pdb.gimp_display_new for that image.
You should be able to accomplish this by simply setting the background color to your desired color and then simply flatten the image which will make all transparent areas become set to the current background color.
pdb.gimp_palette_set_background( 'green' )
image = pdb.gimp_file_load ('myImage.png')
flatLayer = pdb.gimp_image_flatten( image )
pdb.gimp_file_save( image, flatLayer, 'myFlatFile.png' , 'myFlatFile.png')

Loading just a part of a texture in DirectX?

If I have a texture file how would I be able to load up only a part of it using a defined rect (top, left, bottom, right)?
Is it technically possibly to only read in the parts I want to load while leaving the rest of the texture untouched?
What exactly are you trying to achieve. Its pretty simple to load up only a small part of a file into a single texture that encompasses it all. You'll probably need to write your own image parser, though.
If you want to load a partial image into a texture thats the same size as the original image (ie only update the area you are after) then this is relaitvely simple as well. You can LockRcts with a rect that is the area you want you update. You'll still need to write your own image parser though.
Personally in situations like this I prefer to use my own texture format that is already in the format I'm after ...
Look at D3DXCreateTextureFromFileEx: http://msdn.microsoft.com/en-us/library/bb172802%28v=VS.85%29.aspx
Otherwise, load the portion of the data you require yourself into memory, create an empty texture and lock it and copy the data.

Resources