ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating an image file (https://www.excelbanter.com/excel-programming/363927-creating-image-file.html)

Jim[_64_]

Creating an image file
 
I'm looking for some VBA code that will take an appropriately scaled
matrix and turn it into a saved image file of some sort (e.g., BMP).
Can anyone help?


Ron de Bruin

Creating an image file
 
Hi Jim

See Harald's code on David's site
http://www.mvps.org/dmcritchie/excel/xl2gif.htm

Or use this small example to save the selection in C:\

Sub Testing()
Application.ScreenUpdating = False
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

Set ctoTheChartHolder = ActiveSheet.ChartObjects.Add(0, 0, 800, 600)

Set chtTheChart = ctoTheChartHolder.Chart

' Paste the picture onto the chart and
' set an object variable for it
ctoTheChartHolder.Activate
With chtTheChart
.ChartArea.Select
.Paste
Set picThePicture = .Pictures(1)
End With

' Set the picture's properties...
With picThePicture
.Left = 0
.Top = 0
sglWidth = .Width + 7
sglHeight = .Height + 7
End With

' Change the size of the chart object to fit the picture
'better
With ctoTheChartHolder
.Border.LineStyle = xlNone
.Width = sglWidth
.Height = sglHeight
End With
' Export the chart as a graphics file
blnRet = chtTheChart.Export(Filename:="c:\range.gif", _
FilterName:="gif", Interactive:=False)
ctoTheChartHolder.Delete
Application.ScreenUpdating = True
End Sub


--
Regards Ron De Bruin
http://www.rondebruin.nl



"Jim" wrote in message ups.com...
I'm looking for some VBA code that will take an appropriately scaled
matrix and turn it into a saved image file of some sort (e.g., BMP).
Can anyone help?




Jim[_64_]

Creating an image file
 
Thanks Ron. That is some cool stuff. I love it.

But, I guess I wasn't clear about what I wanted.
I'd like to create a gif or a bmp from an array such that each element
of the array contains the color of a single pixel. For instance in a
really simplified example, I'd like to convert the array
{0,63,127,255} into a 1 x 4 image gray-scale image.

Do you have any help for this problem?

Thanks,
Jim


Ron de Bruin

Creating an image file
 
Do you have any help for this problem?

No, sorry

--
Regards Ron De Bruin
http://www.rondebruin.nl



"Jim" wrote in message ups.com...
Thanks Ron. That is some cool stuff. I love it.

But, I guess I wasn't clear about what I wanted.
I'd like to create a gif or a bmp from an array such that each element
of the array contains the color of a single pixel. For instance in a
really simplified example, I'd like to convert the array
{0,63,127,255} into a 1 x 4 image gray-scale image.

Do you have any help for this problem?

Thanks,
Jim





All times are GMT +1. The time now is 12:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com