Hi there.
I'm coming from Python+PIL background. I'm sick of it being so slow for pixel processing. Cython is much better, but I would prefer something that didn't feel awkward to write in. I haven't seen any PIL like graphic libraries for Cora. Are there any?
Also, maybe it's no point in rewriting the square wheel if you can use the shiny round one. Is there any C# library that Cobra can interface to nicely? (new to C# as well as Cobra). I'm looking for something that allows me to do pixel level manipulation at the typical rgb components.
Forums
Looking for a graphic library program
11 posts
• Page 1 of 2 • 1, 2
Re: Looking for a graphic library program
C#, Visual Basic and Cobra all produce "standard .NET libraries" so they can use each other's libraries seamlessly. .NET & Mono include a library called System.Drawing. Here is small program to get you started:
"""
DrawingExample.cobra
Generating bitmap images with the System.Drawing library.
References:
System.Drawing - <!-- m --><a class="postlink" href="http://msdn.microsoft.com/en-us/library/system.drawing.aspx">http://msdn.microsoft.com/en-us/library ... awing.aspx</a><!-- m -->
"""
@ref 'System.Drawing'
@number float64
use System.Drawing
use System.Drawing.Drawing2D
use System.Drawing.Imaging
use System.Drawing.Text
class Program
def main
.saveSample
def saveSample
bm = .makeBitmap
# bm.save('sample.jpg', ImageFormat.jpeg)
bm.save('sample.bmp', ImageFormat.bmp)
print 'Saved: sample.bmp'
print 'done.'
def makeBitmap as Bitmap
width = 480
height = 200
bm = Bitmap(width, height)
g = Graphics.fromImage(bm)
g.clear(Color.forestGreen)
# g.clear(Color.blue)
g.flush
g.smoothingMode = SmoothingMode.AntiAlias
g.textRenderingHint = TextRenderingHint.ClearTypeGridFit
if true
font = Font('Tahoma', 18, FontStyle.Bold)
brush = SolidBrush(Color.white)
g.drawString('The Cobra Programming Language', font, brush, 10, 50)
g.flush
if false
for i, hint in [TextRenderingHint.AntiAlias, TextRenderingHint.AntiAliasGridFit, TextRenderingHint.ClearTypeGridFit].numbered
font = Font('Tahoma', 18, FontStyle.Bold)
brush = SolidBrush(Color.white)
g.textRenderingHint = hint
g.drawString('The Cobra Programming Language', font, brush, 10, 10 + (50 * i))
g.flush
return bm
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Looking for a graphic library program
If you have any more questions or issues, feel free.
I have also attached the program to this message if that makes it easier to get.
-Chuck
I have also attached the program to this message if that makes it easier to get.
-Chuck
- Attachments
-
- DrawingExample.cobra
- (1.37 KiB) Downloaded 341 times
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Looking for a graphic library program
That's a good starting point, thanks. Interesting convention about lower/upper case. What does cobra do if C# has two class methods or variables which are different only in the casing of the first letter?
- gradha
- Posts: 23
Re: Looking for a graphic library program
You'll almost never see this. The reason is that .NET started with (at least) 2 languages: C# and Visual Basic (VB). VB is case insensitive, so people who write libraries avoid such practices. In fact, there is a "Common Language Specification" to avoid these issues. From http://blogs.msdn.com/b/brada/archive/2004/03/20/93341.aspx, "The CLS (or Common Language Specification) is simply a contract between programming language designers and class library authors."
In direct answer to your question, I couldn't remember since I'm not using any such libraries! But I constructed such a library in C#, and Cobra is binding to the first declared method.
Btw I think such a class would be poorly designed. For example, if a Color object had properties "brightness" and "Brightness", what differences between them are implied by a change in case?
In direct answer to your question, I couldn't remember since I'm not using any such libraries! But I constructed such a library in C#, and Cobra is binding to the first declared method.
Btw I think such a class would be poorly designed. For example, if a Color object had properties "brightness" and "Brightness", what differences between them are implied by a change in case?
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Looking for a graphic library program
Certainly the class would be not very nice to use. I only wanted to know if trying to use such a library would make Cobra crash or make the program unstable. I don't expect to find such a fabricated case in real life.
- gradha
- Posts: 23
Re: Looking for a graphic library program
Cool. If you produce any graphics generation code that you can share back, that would be interesting to see.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Looking for a graphic library program
I was expecting to post the Cobra version of my Python program in one week or so to let you critizise it. It's not rocket science, I only process some input images in a way that are useful to me in another program, so I don't think it will be too interesting, especially since it makes assumptions on the input data to treat it correctly, which discards its use for other graphics.
Ouch, now I've remembered that the final part of the Python program calls a custom C module for packaging. Argh, that will be painful to port...
Ouch, now I've remembered that the final part of the Python program calls a custom C module for packaging. Argh, that will be painful to port...
- gradha
- Posts: 23
Re: Looking for a graphic library program
You wrote this C module or its third party? Is it originally plain C code which is then wrapped up in a Python module, or is it a Python module to begin with? What platform are you on?
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Looking for a graphic library program
Custom modifications to an old C lib. I wanted it to work in obj-c on the iPhone and macosx build scripts in python. I guess I'll port it to C# or Cobra directly. It's not much work, just boring.
- gradha
- Posts: 23
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 86 guests